MINIROCKET - fast random convolutional features for time series.

Classes

MiniRocketClassifier

class algorithms.timeseries.classification.rocket.MiniRocketClassifier(TimeSeriesClassifier)

MINIROCKET: near state-of-the-art accuracy at a tiny fraction of the cost.

MINIROCKET convolves each series with a fixed set of 84 dilated kernels and summarises every output by its proportion of positive values (PPV). The resulting few thousand features go to a plain linear classifier. It is almost deterministic — only the bias quantiles are sampled — and it reaches accuracy competitive with far more expensive time-series classifiers while running orders of magnitude faster.
Constructor
__init__(
    self,
    n_features: int = 9996,
    estimator: Optional[Any] = None,
    random_state: Optional[int] = None,
)

Overview

  1. Build the 84 fixed kernels: length 9, weights from {-1, 2} with
exactly three positions holding 2.
  1. Pick exponentially spaced dilations that fit inside the series.
  2. For each kernel and dilation, set biases at quantiles of the actual
convolution output on a sampled training series.
  1. Transform each series to one PPV feature per (kernel, dilation, bias).
  2. Fit a linear classifier on those features.

Theory

Every kernel w has weights in \{-1, 2\} with three 2s, so \sum_i w_i = 3 \cdot 2 + 6 \cdot (-1) = 0. A constant offset therefore cancels wherever the whole kernel overlaps real data — though not at the zero-padded edges, where it does not; see the normalisation note below. The feature for kernel w, dilation d and bias b is

\mathrm{PPV}(X, w, d, b) = \frac{1}{n} \sum_{t} \mathbb{1}\{ (X * _d w)(t) > b \}

PPV, rather than the max pooling used by earlier convolutional transforms, is what carries most of MINIROCKET's accuracy: it measures how often a pattern matches, not merely how strongly it matches once.

The speed comes from an algebraic trick. A kernel is -1 everywhere except at three positions holding +2, so it equals the all--1 kernel plus a correction of +3 at those three positions. The all--1 convolution is computed once per dilation and the nine possible corrections cached, after which each of the 84 kernels costs three vector additions rather than a fresh convolution. That is the difference between MINIROCKET and random-kernel ROCKET.

Parameters

n_features
int = 9996
Approximate number of output features. Rounded down to a multiple of 84 internally. The default follows the paper's 10,000.
estimator
Classifier
Head fitted on the transformed features. Defaults to LogisticRegression. Any TuiML classifier works; the transform is the method, the head is a choice.
random_state
int
Seed for the training series sampled when fitting biases.

Attributes

dilations_
np.ndarray of shape (n_dilations,)
Fitted dilation factors.
features_per_dilation_
np.ndarray of shape (n_dilations,)
Biases allocated to each dilation.
biases_
np.ndarray of shape (n_features_,)
Fitted bias thresholds.
n_features_
int
Actual number of features produced.
estimator_
Classifier
The fitted head.
classes_
np.ndarray of shape (n_classes,)
Class labels seen during fit.

Notes

Complexity. Fitting the transform is O(84 \, k \, L) for k dilations, independent of the training-set size — biases come from sampled series. Transforming is O(n \, 84 \, k \, L), run in parallel over series by the shared C++ kernel tuiml._cpp_ext.timeseries. The head then dominates.

When to use. MINIROCKET is the right default for time-series classification at any scale where DTWNeighborsClassifier is too slow — which is most of them, since DTW's cost grows with the training set while this transform's does not. Unlike DTW it is not warping-invariant: it detects whether patterns occur, at what scale and how often, which is usually what distinguishes classes, but if two classes differ only by a global time-warp DTW remains the better tool.

Measured on a synthetic problem where the class is the frequency of a short burst hidden at a random position, with amplitude, phase, sign and position randomised and each series z-normalised so no energy cue survives (400 train / 400 test, length 256):

=============== ========== =============== model accuracy predict time =============== ========== =============== MINIROCKET 0.983 168 ms Euclidean 1NN 0.895 39 ms DTW-1NN (10%) 0.772 12 935 ms RandomForest 0.590 9 ms =============== ========== ===============

DTW is both the slowest and among the least accurate here, because warping invariance actively smears the frequency information that defines the classes — the same trade-off documented on DTWNeighborsClassifier. Note also what the cost columns do as data grows: on an easier problem, going from 200 to 1000 training series left MINIROCKET's prediction time flat (83 ms to 76 ms) while DTW's rose with the training set (144 ms to 670 ms). That asymptotic difference, not any single benchmark row, is the reason to reach for this first.

Z-normalise each series first. The kernel weights sum to zero, so a constant offset cancels wherever the whole kernel fits inside the series — but the convolution is zero-padded at the edges, where only part of the kernel overlaps real data and the weights no longer cancel. Half the features are scored over that padded range, so offset invariance holds for the valid-centre features and not for the padded ones. Scale is never cancelled. Normalising removes both concerns.

Multivariate input is handled channel-independently: the transform is applied to each channel and the features concatenated. That is a simplification of the paper's multivariate variant, which samples channel subsets per kernel; it costs feature-count efficiency, not correctness, and cross-channel interactions are left to the head.

References

Dempster2021
Dempster, A., Schmidt, D. F., & Webb, G. I. (2021). MINIROCKET: A Very Fast (Almost) Deterministic Transform for Time Series Classification. ACM SIGKDD, 248-257. :doi:`10.1145/3447548.3467231`
Dempster2020
Dempster, A., Petitjean, F., & Webb, G. I. (2020). ROCKET: Exceptionally Fast and Accurate Time Series Classification Using Random Convolutional Kernels. Data Mining and Knowledge Discovery, 34(5), 1454-1495. :doi:`10.1007/s10618-020-00701-z`
python
>>> import numpy as np
>>> from tuiml.algorithms.timeseries.classification import MiniRocketClassifier
>>> rng = np.random.default_rng(0)
>>> t = np.linspace(0, 4 * np.pi, 64)
>>> shifts = rng.uniform(0, 2 * np.pi, 80)
>>> sines = np.sin(t + shifts[:40, None]) + rng.normal(0, 0.1, (40, 64))
>>> squares = np.sign(np.sin(t + shifts[40:, None])) + rng.normal(0, 0.1, (40, 64))
>>> X = np.vstack([sines, squares])
>>> y = np.array([0] * 40 + [1] * 40)
>>> model = MiniRocketClassifier(n_features=840, random_state=0).fit(X, y)
>>> float((model.predict(X) == y).mean())
1.0

Methods

get_parameter_schema (cls) -> Dict[str, Dict[str, Any]]

Return JSON Schema for algorithm parameters.

get_capabilities (cls) -> List[str]

Return supported capabilities.

get_complexity (cls) -> str

Return complexity analysis.

get_references (cls) -> List[str]

Return academic citations.

fit (self, X: np.ndarray, y: np.ndarray) -> 'MiniRocketClassifier'

Fit the transform and the head.

Parameters
X
np.ndarray of shape (n_samples, n_timepoints) or (n_samples, n_channels, n_timepoints)
Training series.
y
np.ndarray of shape (n_samples,)
Training labels.
Returns
self
MiniRocketClassifier
The fitted classifier.
transform (self, X: np.ndarray) -> np.ndarray

Return the PPV feature matrix for a panel of series.

Parameters
X
np.ndarray of shape (n_samples, n_timepoints) or (n_samples, n_channels, n_timepoints)
Series to transform.
Returns
features
np.ndarray of shape (n_samples, n_features_)
One PPV feature per (kernel, dilation, bias), per channel.
predict (self, X: np.ndarray) -> np.ndarray

Classify each series.

Parameters
X
np.ndarray of shape (n_samples, n_timepoints) or (n_samples, n_channels, n_timepoints)
Series to classify.
Returns
y_pred
np.ndarray of shape (n_samples,)
Predicted labels.
predict_proba (self, X: np.ndarray) -> np.ndarray

Return class probabilities from the head.

Parameters
X
np.ndarray of shape (n_samples, n_timepoints) or (n_samples, n_channels, n_timepoints)
Series to classify.
Returns
proba
np.ndarray of shape (n_samples, n_classes)
Class probabilities as reported by the head.
__repr__ (self) -> str

Return a readable representation of the classifier.

MiniRocketTransformer

class algorithms.timeseries.classification.rocket.MiniRocketTransformer(MiniRocketClassifier)

The MINIROCKET transform on its own, with no classifier attached.

Use this to feed MINIROCKET features into a pipeline, a different learner, or a clustering or anomaly method — anywhere the transform is wanted but the classification head is not.
Constructor
__init__(
    self,
    n_features: int = 9996,
    random_state: Optional[int] = None,
)

Parameters

n_features
int = 9996
Approximate number of output features.
random_state
int
Seed for the training series sampled when fitting biases.

Attributes

dilations_
np.ndarray of shape (n_dilations,)
Fitted dilation factors.
biases_
np.ndarray of shape (n_features_,)
Fitted bias thresholds.
n_features_
int
Actual number of features produced.

Notes

Fitting needs no labels. fit accepts y=None.
python
>>> import numpy as np
>>> from tuiml.algorithms.timeseries.classification import MiniRocketTransformer
>>> rng = np.random.default_rng(0)
>>> X = rng.normal(size=(20, 64))
>>> transformer = MiniRocketTransformer(n_features=840, random_state=0).fit(X)
>>> features = transformer.transform(X)
>>> features.shape[0]
20
>>> bool(((features >= 0.0) & (features <= 1.0)).all())  # PPV is a proportion
True

Methods

fit (self, X: np.ndarray, y: Optional[np.ndarray]=None) -> 'MiniRocketTransformer'

Fit the transform. Labels are not used.

Parameters
X
np.ndarray of shape (n_samples, n_timepoints) or (n_samples, n_channels, n_timepoints)
Training series.
y
np.ndarray
Ignored, present for API consistency.
Returns
self
MiniRocketTransformer
The fitted transformer.
fit_transform (self, X: np.ndarray, y: Optional[np.ndarray]=None) -> np.ndarray

Fit the transform and return the features of X.

Parameters
X
np.ndarray of shape (n_samples, n_timepoints) or (n_samples, n_channels, n_timepoints)
Training series.
y
np.ndarray
Ignored, present for API consistency.
Returns
features
np.ndarray of shape (n_samples, n_features_)
PPV features.
predict (self, X: np.ndarray) -> np.ndarray

Not available: this class has no classification head.

Parameters
X
np.ndarray
Ignored.
Raises
NotImplementedError
Always. Use MiniRocketClassifier to classify.
predict_proba (self, X: np.ndarray) -> np.ndarray

Not available: this class has no classification head.

Parameters
X
np.ndarray
Ignored.
Raises
NotImplementedError
Always.
__repr__ (self) -> str

Return a readable representation of the transformer.