ShapeletTreeStumpClassifier#
- class ShapeletTreeStumpClassifier(n_shapelets=8, n_shapelets_for_selection=500, n_ts_for_selection_per_class=100, sliding_window=50, selection='mi_clf', distance='euclidean', mi_n_neighbors=100, random_state=42, n_jobs=1, criterion='gini', min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=None, min_impurity_decrease=0.0, class_weight=None)[source]#
Bases:
ShapeletTreeStump,DecisionTreeStumpClassifierShapelet stump for classification of time series: a threshold on the distance of the time series from a shapelet (
distance <= tgoes left).A shapelet is a subsequence of one of the time series of the node; the distance of a time series from it is the smallest distance between the shapelet and the subsequences of the series, so it does not depend on where the pattern occurs. At each node,
n_shapeletsshapelets are selected among candidate subsequences, and the split is the best threshold on the distance from one of them. In the rules,euclidean(TS, shp)is the distance from the shapelet.It is a
Stumpmade of a ShapeletTransformer and a ClassificationSplitter. The time series have shape (n_samples, n_signals, length) and are passed to the trees asX_ts.- Parameters:
n_shapelets (int, default=8) – Number of shapelets selected at each node.
n_shapelets_for_selection (int, numpy.inf or 'stratified', default=500) – Number of candidate subsequences extracted from the time series, among which the shapelets are selected. ‘stratified’ draws them according to the class distribution.
n_ts_for_selection_per_class (int or numpy.inf, default=100) – Number of time series of each class from which the candidates are extracted.
sliding_window (int, default=50) – Length of the shapelets.
selection ({'random', 'mi_clf', 'cluster'}, default='mi_clf') – How the shapelets are selected among the candidates: at random, by mutual information with the target, or as the medoids of a k-medoids clustering (requires scikit-learn-extra).
distance ({'euclidean', 'sqeuclidean', 'cosine', 'cityblock'} or callable, default='euclidean') – Distance between a shapelet and a subsequence; the distance of a time series from a shapelet is the minimum over the positions of the shapelet.
mi_n_neighbors (int, default=100) – Number of neighbors used to estimate the mutual information.
random_state (int, default=42) – Seed of the random choices of the candidates and of the shapelets.
n_jobs (int, default=1) – Number of threads used to compute the distances (-1: all the CPUs).
criterion ({'gini', 'entropy'}, default='gini') – Impurity measure.
min_samples_leaf (int or float, default=1) – Minimum number of instances in each child (a fraction of the instances of the node if float). Applies to the numerical features.
min_weight_fraction_leaf (float, default=0.0) – Minimum fraction of the sample weights of the node in each child. Applies to the numerical features.
max_features (int, float, {'sqrt', 'log2'} or None, default=None) – Number of numerical features considered for the split, drawn at random; None for all.
min_impurity_decrease (float, default=0.0) – A numerical split is kept only if it decreases the weighted impurity by at least this value.
class_weight (dict, 'balanced' or None, default=None) – Weights of the classes in the impurity; ‘balanced’ weighs them inversely to their frequency.
- Variables:
transformer (ShapeletTransformer) – The fitted transformer.
splitter (ClassificationSplitter) – The fitted splitter (feature, threshold, gain and impurity of the split).
data_type (str) – Data type the stump was fitted on.
feature_original (int) – Index of the shapelet of the split among the selected ones.
threshold_original (float) – Threshold of the split.
See also
ShapeletTreeStumpRegressorthe same stump for regression.
RuleTree.utils.shapelet_transform.Shapelets.Shapeletsthe selection of the shapelets.
Examples
>>> import numpy as np >>> from RuleTree import RuleTreeClassifier >>> from RuleTree.stumps.classification import ShapeletTreeStumpClassifier >>> rng = np.random.default_rng(0) >>> X_ts = rng.normal(size=(60, 1, 30)) # 60 time series of length 30 >>> y = rng.integers(0, 2, size=60) >>> stump = ShapeletTreeStumpClassifier(n_shapelets=5, sliding_window=10, selection="random") >>> model = RuleTreeClassifier(max_depth=2, base_stumps=stump).fit(X_ts=X_ts, y=y) >>> model.predict(X_ts=X_ts).shape (60,)