# `tslearn.matrix_profile`.MatrixProfile¶

class tslearn.matrix_profile.MatrixProfile(subsequence_length=1, implementation='numpy', scale=True)[source]

Matrix Profile transformation.

Matrix Profile was originally presented in [1].

Parameters:
subsequence_lengthint (default: 1)

Length of the subseries (also called window size) to be used for subseries distance computations.

implementationstr (default: “numpy”)

Matrix profile implementation to use. Defaults to “numpy” to use the pure numpy version. All the available implementations are [“numpy”, “stump”, “gpu_stump”].

“stump” and “gpu_stump” are both implementations from the stumpy python library, the latter requiring a GPU. Stumpy is a library for efficiently computing the matrix profile which is optimized for speed, performance and memory. See [2] for the documentation. “numpy” is the default pure numpy implementation and does not require stumpy to be installed.

scale: bool (default: True)

Whether input data should be scaled for each feature of each time series to have zero mean and unit variance. Default for this parameter is set to True to match the standard matrix profile setup.

References

[1]

C. M. Yeh, Y. Zhu, L. Ulanova, N.Begum et al. Matrix Profile I: All Pairs Similarity Joins for Time Series: A Unifying View that Includes Motifs, Discords and Shapelets. ICDM 2016.

Examples

```>>> time_series = [0., 1., 3., 2., 9., 1., 14., 15., 1., 2., 2., 10., 7.]
>>> ds = [time_series]
>>> mp = MatrixProfile(subsequence_length=4, scale=False)
>>> mp.fit_transform(ds)[0, :, 0]
array([ 6.85...,  1.41...,  6.16...,  7.93..., 11.40...,
13.56..., 18.  ..., 13.96...,  1.41...,  6.16...])
```

Methods

 `fit`(X[, y]) Fit a Matrix Profile representation. `fit_transform`(X[, y]) Transform a dataset of time series into its Matrix Profile `from_hdf5`(path) Load model from a HDF5 file. `from_json`(path) Load model from a JSON file. `from_pickle`(path) Load model from a pickle file. Get metadata routing of this object. `get_params`([deep]) Get parameters for this estimator. `set_output`(*[, transform]) Set output container. `set_params`(**params) Set the parameters of this estimator. `to_hdf5`(path) Save model to a HDF5 file. `to_json`(path) Save model to a JSON file. `to_pickle`(path) Save model to a pickle file. `transform`(X[, y]) Transform a dataset of time series into its Matrix Profile
fit(X, y=None)[source]

Fit a Matrix Profile representation.

Parameters:
Xarray-like of shape (n_ts, sz, d)

Time series dataset

Returns:
MatrixProfile

self

fit_transform(X, y=None, **fit_params)[source]
Transform a dataset of time series into its Matrix Profile

representation.

Parameters:
Xarray-like of shape (n_ts, sz, d)

Time series dataset

Returns:
numpy.ndarray of shape (n_ts, output_size, 1)

Matrix-Profile-Transformed dataset. ouput_size is equal to sz - subsequence_length + 1

classmethod from_hdf5(path)[source]

Load model from a HDF5 file. Requires `h5py` http://docs.h5py.org/

Parameters:
pathstr

Full path to file.

Returns:
Model instance
classmethod from_json(path)[source]

Load model from a JSON file.

Parameters:
pathstr

Full path to file.

Returns:
Model instance
classmethod from_pickle(path)[source]

Load model from a pickle file.

Parameters:
pathstr

Full path to file.

Returns:
Model instance

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

A `MetadataRequest` encapsulating routing information.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

set_output(*, transform=None)[source]

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters:
transform{“default”, “pandas”}, default=None

Configure output of transform and fit_transform.

• “default”: Default output format of a transformer

• “pandas”: DataFrame output

• None: Transform configuration is unchanged

Returns:
selfestimator instance

Estimator instance.

set_params(**params)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as `Pipeline`). The latter have parameters of the form `<component>__<parameter>` so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

to_hdf5(path)[source]

Save model to a HDF5 file. Requires `h5py` http://docs.h5py.org/

Parameters:
pathstr

Full file path. File must not already exist.

Raises:
FileExistsError

If a file with the same path already exists.

to_json(path)[source]

Save model to a JSON file.

Parameters:
pathstr

Full file path.

to_pickle(path)[source]

Save model to a pickle file.

Parameters:
pathstr

Full file path.

transform(X, y=None)[source]
Transform a dataset of time series into its Matrix Profile

representation.

Parameters:
Xarray-like of shape (n_ts, sz, d)

Time series dataset

Returns:
numpy.ndarray of shape (n_ts, output_size, 1)

Matrix-Profile-Transformed dataset. ouput_size is equal to sz - subsequence_length + 1

## Examples using `tslearn.matrix_profile.MatrixProfile`¶

Matrix Profile

Matrix Profile

Distance and Matrix Profiles

Distance and Matrix Profiles