SAXVSM#
- class pyts.classification.SAXVSM(window_size: int | float = 0.5, word_size: int | float = 0.5, n_bins: int = 4, strategy: str = 'normal', numerosity_reduction: bool = True, window_step: int | float = 1, threshold_std: int | float | None = 0.01, norm_mean: bool = True, norm_std: bool = True, use_idf: bool = True, smooth_idf: bool = False, sublinear_tf: bool = True, overlapping: bool = True, alphabet: ArrayLike | None = None)[source]#
Classifier based on SAX-VSM representation and tf-idf statistics.
Time series are first transformed into bag of words using Symbolic Aggregate approXimation (SAX) algorithm followed by a bag-of-words model. Then the classes are transformed into a Vector Space Model (VSM) using term frequencies (tf) and inverse document frequencies (idf).
- Parameters:
- window_sizeint or float (default = 0.5)
Length of the sliding window. If float, it represents a percentage of the size of each time series and must be between 0 and 1.
- word_sizeint or float (default = 0.5)
Length of the words. If float, it represents a percentage of the length of the sliding window and must be between 0. and 1.
- n_binsint (default = 4)
The number of bins to produce. It must be between 2 and
min(window_size, 26).- strategy‘uniform’, ‘quantile’ or ‘normal’ (default = ‘normal’)
Strategy used to define the widths of the bins:
‘uniform’: All bins in each sample have identical widths
‘quantile’: All bins in each sample have the same number of points
‘normal’: Bin edges are quantiles from a standard normal distribution
- numerosity_reductionbool (default = True)
If True, delete sample-wise all but one occurence of back to back identical occurences of the same words.
- window_stepint or float (default = 1)
Step of the sliding window. If float, it represents the percentage of the size of each time series and must be between 0 and 1. The step of sliding window will be computed as
ceil(window_step * n_timestamps).- threshold_std: float (default = 0.01)
Threshold used to determine whether a subsequence is standardized. Subsequences whose standard deviations are lower than this threshold are not standardized.
- norm_meanbool (default = True)
If True, center each subseries before scaling.
- norm_stdbool (default = True)
If True, scale each subseries to unit variance.
- use_idfbool (default = True)
Enable inverse-document-frequency reweighting.
- smooth_idfbool (default = False)
Smooth idf weights by adding one to document frequencies, as if an extra document was seen containing every term in the collection exactly once. Prevents zero divisions.
- sublinear_tfbool (default = True)
Apply sublinear tf scaling, i.e. replace tf with 1 + log(tf).
- overlappingbool (default = True)
If True, time points may belong to two bins when decreasing the size of the subsequence with the Piecewise Aggregate Approximation algorithm. If False, each time point belong to one single bin, but the size of the bins may vary.
- alphabetNone or array-like, shape = (n_bins,)
Alphabet to use. If None, the first n_bins letters of the Latin alphabet are used.
- Attributes:
- classes_array, shape = (n_classes,)
An array of class labels known to the classifier.
- idf_array, shape = (n_features,) , or None
The learned idf vector (global term weights) when
use_idf=True, None otherwise.- tfidf_array, shape = (n_classes, n_words)
Term-document matrix.
- vocabulary_dict
A mapping of feature indices to terms.
References
[1]P. Senin, and S. Malinchik, “SAX-VSM: Interpretable Time Series Classification Using SAX and Vector Space Model”. International Conference on Data Mining, 13, 1175-1180 (2013).
Examples
>>> from pyts.classification import SAXVSM >>> from pyts.datasets import load_gunpoint >>> X_train, X_test, y_train, y_test = load_gunpoint(return_X_y=True) >>> clf = SAXVSM(window_size=64, word_size=12, n_bins=5, strategy='normal') >>> clf.fit(X_train, y_train) SAXVSM(...) >>> clf.score(X_test, y_test) 1.0
Methods
__init__([window_size, word_size, n_bins, ...])Evaluate the cosine similarity between document-term matrix and X.
fit(X, y)Fit the model according to the given training data.
get_metadata_routing()Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
predict(X)Predict the class labels for the provided data.
score(X, y[, sample_weight])Return the mean accuracy on the given test data and labels.
set_params(**params)Set the parameters of this estimator.
set_score_request(*[, sample_weight])Configure whether metadata should be requested to be passed to the
scoremethod.- __init__(window_size: int | float = 0.5, word_size: int | float = 0.5, n_bins: int = 4, strategy: str = 'normal', numerosity_reduction: bool = True, window_step: int | float = 1, threshold_std: int | float | None = 0.01, norm_mean: bool = True, norm_std: bool = True, use_idf: bool = True, smooth_idf: bool = False, sublinear_tf: bool = True, overlapping: bool = True, alphabet: ArrayLike | None = None) None[source]#
- decision_function(X: ArrayLike) NDArray[float64][source]#
Evaluate the cosine similarity between document-term matrix and X.
- Parameters:
- Xarray-like, shape (n_samples, n_timestamps)
Test samples.
- Returns:
- Xarray-like, shape (n_samples, n_classes)
osine similarity between the document-term matrix and X.
- fit(X: ArrayLike, y: ArrayLike) Self[source]#
Fit the model according to the given training data.
- Parameters:
- Xarray-like, shape = (n_samples, n_timestamps)
Training vector.
- yarray-like, shape = (n_samples,)
Class labels for each data sample.
- Returns:
- selfobject
- predict(X: ArrayLike) NDArray[Any][source]#
Predict the class labels for the provided data.
- Parameters:
- Xarray-like, shape = (n_samples, n_timestamps)
Test samples.
- Returns:
- y_predarray-like, shape = (n_samples,)
Class labels for each data sample.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') SAXVSM#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
- Returns:
- selfobject
The updated object.
Examples using pyts.classification.SAXVSM#
Symbolic Aggregate approXimation in Vector Space Model (SAX-VSM)