tslearn.piecewise
.OneD_SymbolicAggregateApproximation¶

class
tslearn.piecewise.
OneD_SymbolicAggregateApproximation
(n_segments=1, alphabet_size_avg=5, alphabet_size_slope=5, sigma_l=None, scale=False)[source]¶ OneD Symbolic Aggregate approXimation (1dSAX) transformation.
1dSAX was originally presented in [1].
Parameters:  n_segments : int (default: 1)
Number of PAA segments to compute.
 alphabet_size_avg : int (default: 5)
Number of SAX symbols to use to describe average values.
 alphabet_size_slope : int (default: 5)
Number of SAX symbols to use to describe slopes.
 sigma_l : float or None (default: None)
Scale parameter of the Gaussian distribution used to quantize slopes. If None, the formula given in [1] is used: \(\sigma_L = \sqrt{0.03 / L}\) where \(L\) is the length of each segment.
 scale: bool (default: False)
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 False in version 0.4 to ensure backward compatibility, but is likely to change in a future version.
Attributes:  breakpoints_avg_ : numpy.ndarray of shape (alphabet_size_avg  1, )
List of breakpoints used to generate SAX symbols for average values.
 breakpoints_slope_ : numpy.ndarray of shape (alphabet_size_slope  1, )
List of breakpoints used to generate SAX symbols for slopes.
Notes
This method requires a dataset of equalsized time series.
References
[1] (1, 2) S. Malinowski, T. Guyet, R. Quiniou, R. Tavenard. 1dSAX: a Novel Symbolic Representation for Time Series. IDA 2013. Examples
>>> one_d_sax = OneD_SymbolicAggregateApproximation(n_segments=3, ... alphabet_size_avg=2, alphabet_size_slope=2, sigma_l=1.) >>> data = [[1., 2., 0.1, 1., 1., 1.], [1., 3.2, 1., 3., 1., 1.]] >>> one_d_sax_data = one_d_sax.fit_transform(data) >>> one_d_sax_data.shape (2, 3, 2) >>> one_d_sax_data array([[[1, 1], [0, 0], [1, 0]], <BLANKLINE> [[1, 1], [0, 0], [1, 0]]]) >>> one_d_sax.distance_sax(one_d_sax_data[0], one_d_sax_data[1]) 0.0 >>> one_d_sax.distance(data[0], data[1]) 0.0 >>> one_d_sax.inverse_transform(one_d_sax_data) array([[[ 0.33724488], [ 1.01173463], [0.33724488], [1.01173463], [ 1.01173463], [ 0.33724488]], <BLANKLINE> [[ 0.33724488], [ 1.01173463], [0.33724488], [1.01173463], [ 1.01173463], [ 0.33724488]]]) >>> one_d_sax.fit(data).sigma_l 1.0
Methods
distance
(ts1, ts2)Compute distance between 1dSAX representations as defined in [1]. distance_1d_sax
(sax1, sax2)Compute distance between 1dSAX representations as defined in [1]. distance_paa
(paa1, paa2)Compute distance between PAA representations as defined in [1]. distance_sax
(sax1, sax2)Compute distance between SAX representations as defined in [1]. fit
(X[, y])Fit a 1dSAX representation. fit_transform
(X[, y])Fit a 1dSAX 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 1dSAX 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 1dSAX representation. 
distance
(ts1, ts2)[source]¶ Compute distance between 1dSAX representations as defined in [1].
Parameters:  ts1 : arraylike
A time series
 ts2 : arraylike
Another time series
Returns:  float
1dSAX distance
References
[1] (1, 2) S. Malinowski, T. Guyet, R. Quiniou, R. Tavenard. 1dSAX: a Novel Symbolic Representation for Time Series. IDA 2013.

distance_1d_sax
(sax1, sax2)[source]¶ Compute distance between 1dSAX representations as defined in [1].
Parameters:  sax1 : arraylike
1dSAX representation of a time series
 sax2 : arraylike
1dSAX representation of another time series
Returns:  float
1dSAX distance
Notes
Unlike SAX distance, 1dSAX distance does not lower bound Euclidean distance between original time series.
References
[1] (1, 2) S. Malinowski, T. Guyet, R. Quiniou, R. Tavenard. 1dSAX: a Novel Symbolic Representation for Time Series. IDA 2013.

distance_paa
(paa1, paa2)[source]¶ Compute distance between PAA representations as defined in [1].
Parameters:  paa1 : arraylike
PAA representation of a time series
 paa2 : arraylike
PAA representation of another time series
Returns:  float
PAA distance
References
[1] (1, 2) E. Keogh & M. Pazzani. Scaling up dynamic time warping for datamining applications. SIGKDD 2000, pp. 285–289.

distance_sax
(sax1, sax2)[source]¶ Compute distance between SAX representations as defined in [1].
Parameters:  sax1 : arraylike
SAX representation of a time series
 sax2 : arraylike
SAX representation of another time series
Returns:  float
SAX distance
References
[1] (1, 2) J. Lin, E. Keogh, L. Wei, et al. Experiencing SAX: a novel symbolic representation of time series. Data Mining and Knowledge Discovery, 2007. vol. 15(107)

fit
(X, y=None)[source]¶ Fit a 1dSAX representation.
Parameters:  X : arraylike of shape (n_ts, sz, d)
Time series dataset
Returns:  OneD_SymbolicAggregateApproximation
self

fit_transform
(X, y=None, **fit_params)[source]¶ Fit a 1dSAX representation and transform the data accordingly.
Parameters:  X : arraylike of shape (n_ts, sz, d)
Time series dataset
Returns:  numpy.ndarray of integers with shape (n_ts, n_segments, 2 * d)
1dSAXTransformed dataset. The order of the last dimension is: first d elements represent average values (standard SAX symbols) and the last d are for slopes

classmethod
from_hdf5
(path)[source]¶ Load model from a HDF5 file. Requires
h5py
http://docs.h5py.org/Parameters:  path : str
Full path to file.
Returns:  Model instance

classmethod
from_json
(path)[source]¶ Load model from a JSON file.
Parameters:  path : str
Full path to file.
Returns:  Model instance

classmethod
from_pickle
(path)[source]¶ Load model from a pickle file.
Parameters:  path : str
Full path to file.
Returns:  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.
Returns:  params : dict
Parameter names mapped to their values.

inverse_transform
(X)[source]¶ Compute time series corresponding to given 1dSAX representations.
Parameters:  X : arraylike of shape (n_ts, sz_sax, 2 * d)
A dataset of SAX series.
Returns:  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.
Returns:  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.
Raises:  FileExistsError
If a file with the same path already exists.