# tslearn.piecewise.PiecewiseAggregateApproximation¶

class tslearn.piecewise.PiecewiseAggregateApproximation(n_segments=1)[source]

Piecewise Aggregate Approximation (PAA) transformation.

PAA was originally presented in .

Parameters: n_segments : int (default: 1) Number of PAA segments to compute

Notes

This method requires a dataset of equal-sized time series.

References

  E. Keogh & M. Pazzani. Scaling up dynamic time warping for datamining applications. SIGKDD 2000, pp. 285–289.

Examples

>>> paa = PiecewiseAggregateApproximation(n_segments=3)
>>> data = [[-1., 2., 0.1, -1., 1., -1.], [1., 3.2, -1., -3., 1., -1.]]
>>> paa_data = paa.fit_transform(data)
>>> paa_data.shape
(2, 3, 1)
>>> paa_data
array([[[ 0.5 ],
[-0.45],
[ 0.  ]],
<BLANKLINE>
[[ 2.1 ],
[-2.  ],
[ 0.  ]]])
>>> paa.distance_paa(paa_data, paa_data)  # doctest: +ELLIPSIS
3.15039...
>>> paa.distance(data, data)  # doctest: +ELLIPSIS
3.15039...
>>> paa.inverse_transform(paa_data)
array([[[ 0.5 ],
[ 0.5 ],
[-0.45],
[-0.45],
[ 0.  ],
[ 0.  ]],
<BLANKLINE>
[[ 2.1 ],
[ 2.1 ],
[-2.  ],
[-2.  ],
[ 0.  ],
[ 0.  ]]])


Methods

 distance(ts1, ts2) Compute distance between PAA representations as defined in . distance_paa(paa1, paa2) Compute distance between PAA representations as defined in . fit(X[, y]) Fit a PAA representation. fit_transform(X[, y]) Fit a PAA representation and transform the data accordingly. 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. inverse_transform(X) Compute time series corresponding to given PAA representations. 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 PAA representation.
distance(ts1, ts2)[source]

Compute distance between PAA representations as defined in .

Parameters: ts1 : array-like A time series ts2 : array-like Another time series float PAA distance

References

  (1, 2) E. Keogh & M. Pazzani. Scaling up dynamic time warping for datamining applications. SIGKDD 2000, pp. 285–289.
distance_paa(paa1, paa2)[source]

Compute distance between PAA representations as defined in .

Parameters: paa1 : array-like PAA representation of a time series paa2 : array-like PAA representation of another time series float PAA distance

References

  (1, 2) E. Keogh & M. Pazzani. Scaling up dynamic time warping for datamining applications. SIGKDD 2000, pp. 285–289.
fit(X, y=None)[source]

Fit a PAA representation.

Parameters: X : array-like of shape (n_ts, sz, d) Time series dataset PiecewiseAggregateApproximation self
fit_transform(X, y=None, **fit_params)[source]

Fit a PAA representation and transform the data accordingly.

Parameters: X : array-like of shape (n_ts, sz, d) Time series dataset numpy.ndarray of shape (n_ts, n_segments, d) PAA-Transformed dataset
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.
inverse_transform(X)[source]

Compute time series corresponding to given PAA representations.

Parameters: X : array-like of shape (n_ts, sz_paa, d) A dataset of PAA series. numpy.ndarray of shape (n_ts, sz_original_ts, d) A dataset of time series corresponding to the provided representation.
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 PAA representation.

Parameters: X : array-like of shape (n_ts, sz, d) Time series dataset numpy.ndarray of shape (n_ts, n_segments, d) PAA-Transformed dataset

## Examples using tslearn.piecewise.PiecewiseAggregateApproximation¶ PAA and SAX features