# 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 .

Parameters: subsequence_length : int (default: 1) Length of the subseries (also called window size) to be used for subseries distance computations. implementation : str (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  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

  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]  # doctest: +ELLIPSIS
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_params([deep]) Get parameters for this estimator. 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: X : array-like of shape (n_ts, sz, d) Time series dataset MatrixProfile self
fit_transform(X, y=None, **fit_params)[source]
Transform a dataset of time series into its Matrix Profile
representation.
Parameters: X : array-like of shape (n_ts, sz, d) Time series dataset 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: path : str Full path to file. Model instance
classmethod from_json(path)[source]

Load model from a JSON file.

Parameters: path : str Full path to file. Model instance
classmethod from_pickle(path)[source]

Load model from a pickle file.

Parameters: path : str Full path to file. Model instance
get_params(deep=True)[source]

Get parameters for this estimator.

Parameters: deep : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators. params : dict Parameter names mapped to their values.
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: **params : dict Estimator parameters. self : estimator instance Estimator instance.
to_hdf5(path)[source]

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

Parameters: path : str Full file path. File must not already exist. FileExistsError If a file with the same path already exists.
to_json(path)[source]

Save model to a JSON file.

Parameters: path : str Full file path.
to_pickle(path)[source]

Save model to a pickle file.

Parameters: path : str Full file path.
transform(X, y=None)[source]
Transform a dataset of time series into its Matrix Profile
representation.
Parameters: X : array-like of shape (n_ts, sz, d) Time series dataset 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 Distance and Matrix Profiles