ProximityTransformer#
- class ProximityTransformer(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, ml_task='clf')[source]#
Bases:
ProximityComparisons,ShapeletTransformerTransformer of time series into proximity comparisons: for each pair of shapelets, whether the time series is closer to the second one than to the first.
The shapelets are selected as in
ShapeletTransformer; the feature matrix has one 0/1 column for each pair of them (seecloser_to_second()), so that a split sends left the time series closer to the first shapelet of a pair. After the splitter has chosen a pair, only its two shapelets are kept (select).- Parameters:
n_shapelets (int, default=8) – Number of shapelets selected at each node (at least 2).
n_shapelets_for_selection (int, numpy.inf or 'stratified', default=500) – Number of candidate subsequences, among which the shapelets are selected.
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', 'mi_reg', 'cluster'}, default='mi_clf') – How the shapelets are selected among the candidates.
distance ({'euclidean', 'sqeuclidean', 'cosine', 'cityblock'} or callable, default='euclidean') – Distance between a shapelet and a subsequence.
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).
ml_task ({MODEL_TYPE_CLF, MODEL_TYPE_REG}, default=MODEL_TYPE_CLF) – Task of the stump: for classification, the candidates are drawn from the time series of each class; for regression (also with several targets), from all the time series.
- Variables:
numerical (list of int) – Numerical columns of the feature matrix.
categorical (list of int) – Categorical columns of the feature matrix (none).
st (Shapelets) – The fitted shapelet transform (only the two shapelets of the chosen pair after
select).pairs (list of tuple) – Pairs of shapelets of the columns of the feature matrix.
See also
ProximityTreeStumpClassifier,ProximityTreeStumpRegressorPartialProximityTransformerthe same comparisons with partial pivots, for tabular data.
Examples
>>> import numpy as np >>> from RuleTree.stumps.transformers import ProximityTransformer >>> rng = np.random.default_rng(0) >>> X_ts, y = rng.normal(size=(20, 1, 30)), rng.integers(0, 2, size=20) >>> transformer = ProximityTransformer(n_shapelets=4, sliding_window=5, selection="random") >>> transformer = transformer.fit(X_ts, y, context=None, node_id=None, cache=None) >>> transformer.transform(X_ts).shape # one column for each of the 6 pairs of shapelets (20, 6)
- fit(X, y, idx=None, data_type=None, sample_weight=None, *, context, node_id, cache)[source]#
Select the shapelets among the subsequences of the time series in the node.
- Parameters:
X (numpy.ndarray) – Time series, all the instances.
y (numpy.ndarray) – Target, all the instances.
idx (numpy.ndarray, default=None) – Indices of the instances in the node. If None, all the instances.
data_type (str, default=None) – Type of X, used as key of the cached values.
sample_weight (numpy.ndarray, default=None) – Not supported: must be None.
context (RuleTree or None) – Tree being built, None outside a tree.
node_id (str or None) – Identifier of the node, e.g.
"Rl"(context.get_node_by_id(node_id)), None outside a tree.cache (dict or None) – Cache of the tree (namespace -> dictionary of values), None outside a tree: the component decides whether and how to use it (the ones of the library use
self._get_cache(cache)).
- Returns:
self
- Return type:
- Raises:
ValueError – If sample_weight is given.
NoSplitFoundWarning – If fewer than two shapelets are selected.