TabularShapelets#
- class TabularShapelets(n_shapelets=100, n_ts_for_selection=inf, n_features_strategy=2, selection='random', distance='euclidean', use_combination=True, random_state=42, n_jobs=1)[source]#
Bases:
TransformerMixinTransform of tabular data into distances from partial pivots: instances restricted to a subset of their features (the other features are nan). The distance of an instance from a partial pivot is computed only on the features of the pivot.
The subsets of features (
n_features_strategy) and then the pivots (selection) are chosen on a sample of the training instances.- Parameters:
n_shapelets (int or numpy.inf, default=100) – Number of partial pivots (numpy.inf with selection=’all’).
n_ts_for_selection (int, float or numpy.inf, default=numpy.inf) – Number (int) or fraction (float) of the training instances used to select the pivots.
n_features_strategy (int, float, tuple or str, default=2) – Number of features of the pivots: an int, a fraction of the features (float), a range
(min, max)(tuple), or chosen from the feature importances of a random forest (‘elbow’, ‘drop’, ‘new’) or iteratively with depth-1 trees (‘iterative’).selection ({'random', 'cluster', 'all'}, default='random') – How the pivots are selected among the candidates: at random (stratified by number of features), the instances closest to k-means centroids, or all of them.
distance ({'euclidean', 'sqeuclidean', 'cosine', 'cityblock'} or callable, default='euclidean') – Distance between an instance and a pivot.
use_combination (bool, default=True) – With the strategies based on feature importances, whether to use all the combinations of the important features or only the set of all of them.
random_state (int, default=42) – Seed of the random choices.
n_jobs (int, default=1) – Number of threads used to compute the distances (-1: all the CPUs).
- Variables:
shapelets (numpy.ndarray of shape (n_shapelets, n_features)) – The partial pivots (nan for the features not used).
subsequences_index (dict) – Number of features -> list of the subsets of features used.
- Raises:
UnsupportedError – For an unknown distance or selection, or an n_shapelets inconsistent with the selection.
- fit(X, y=None, **fit_params)[source]#
Fit the TabularShapelets transformer on training data.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training tabular data.
y (array-like of shape (n_samples,), default=None) – Target values for supervised learning.
**fit_params (dict) – Additional parameters passed to selection methods.
- Returns:
self – Returns self.
- Return type:
- transform(X, y=None)[source]#
Distance of each instance from each partial pivot.
- Parameters:
X (numpy.ndarray of shape (n_samples, n_features))
y (None) – Not used.
- Returns:
distances
- Return type:
numpy.ndarray of shape (n_samples, n_shapelets)