Shapelets#

class Shapelets(n_shapelets=100, n_shapelets_for_selection=inf, n_ts_for_selection_per_class=inf, sliding_window=50, selection='random', distance='euclidean', mi_n_neighbors=100, random_state=42, n_jobs=1, ml_task='clf')[source]#

Bases: TransformerMixin

Shapelets transformer for time series classification.

This class implements the shapelet transform method which transforms time series data into a feature vector of distances between the time series and a set of shapelets. Shapelets are discriminative subsequences extracted from the time series.

The transformer follows scikit-learn’s TransformerMixin interface (fit, transform).

Parameters:
  • n_shapelets (int, default=100) – Number of shapelets to be used in the transformation.

  • n_shapelets_for_selection (int or str, default=np.inf) – Number of candidate shapelets to generate before selection, drawn at random: for classification, the same number from the time series of each class. If ‘stratified’, the square root of the number of time series, from each class in proportion to its size. If np.inf, all the subsequences of the time series.

  • n_ts_for_selection_per_class (int, default=np.inf) – Number of time series of each class (of all the time series, for regression) from which the candidates are drawn, chosen at random.

  • sliding_window (int, default=50) – Length of the shapelets to extract.

  • selection (str, default='random') – Method used to select the final shapelets from candidates: - ‘random’: random selection - ‘mi_clf’: mutual information (classification) - ‘mi_reg’: mutual information (regression) - ‘cluster’: KMedoids clustering

  • distance (str or callable, default='euclidean') – Distance metric to use for computing distances between shapelets and time series. Options: ‘euclidean’, ‘sqeuclidean’, ‘cosine’, ‘cityblock’, or custom callable.

  • mi_n_neighbors (int, default=100) – Number of neighbors to use for mutual information calculation.

  • random_state (int, default=42) – Random seed for reproducibility.

  • n_jobs (int, default=1) – Number of parallel jobs. If -1, uses all available processors.

  • ml_task ({MODEL_TYPE_CLF, MODEL_TYPE_REG}, default=MODEL_TYPE_CLF) – Task of the target: for classification, the candidates are drawn from each class; for regression (also with several targets), from all the time series.

fit(X, y=None)[source]#

Fit the Shapelets transformer on training data.

Parameters:
  • X (array-like of shape (n_samples, n_signals, n_timepoints)) – Training time series data. Currently only supports n_signals=1 (univariate time series).

  • y (array-like of shape (n_samples,), default=None) – Target values for supervised learning.

Returns:

self – Returns self.

Return type:

Shapelets

Raises:

NotImplementedError – If multivariate time series are provided (n_signals > 1).

transform(X, y=None)[source]#

Transform time series data into shapelet distance features.

For each time series in X, computes the minimum distance to each shapelet, resulting in a feature vector of length n_shapelets.

Parameters:
  • X (array-like of shape (n_samples, n_signals, n_timepoints)) – Time series data to transform.

  • y (array-like of shape (n_samples,), default=None) – Target values (unused in transformation).

Returns:

Transformed data, where each feature is the minimum distance between a time series and a shapelet.

Return type:

array-like of shape (n_samples, n_shapelets)