RocketClassifier<T>
Models & Types · AiDotNet.Classification.TimeSeries
Implements ROCKET (Random Convolutional Kernel Transform) for time series classification.
Inheritance: ClassifierBase<T> → RocketClassifier<T>
Implements: IGeneratedParameterRegistrar<T>, ITimeSeriesClassifier<T>
For Beginners
ROCKET is a highly efficient and accurate time series classifier that uses thousands of random convolutional kernels to extract features. Despite using random kernels (no training), it achieves state-of-the-art accuracy while being orders of magnitude faster than other methods.
How It Works
How ROCKET works:
- Generate thousands of random convolutional kernels with varying lengths, dilations, and weights
- Apply each kernel to the input time series to produce an output array
- Extract two features from each kernel output: max value and proportion of positive values (PPV)
- Use these features with a simple linear classifier (e.g., Ridge regression)
Why ROCKET is so effective:
- Random kernels + large quantity = covers diverse patterns
- PPV captures frequency of pattern occurrence
- Max value captures pattern strength
- Dilation handles different time scales
Reference: Dempster et al., “ROCKET: Exceptionally fast and accurate time series classification using random convolutional kernels” (2020)
Example
// Create ROCKET classifier with short kernel lengths matching the data
var options = new RocketOptions<double> { KernelLengths = new[] { 3, 5 } };
// Prepare time series data: rows are samples, columns are time steps
// Series length must be >= max kernel length
var features = new Matrix<double>(4, 8);
// Class 0: low-amplitude oscillation
features[0, 0] = 1.0; features[0, 1] = 1.2; features[0, 2] = 1.5; features[0, 3] = 1.3;
features[0, 4] = 1.1; features[0, 5] = 1.4; features[0, 6] = 1.2; features[0, 7] = 1.0;
features[1, 0] = 1.1; features[1, 1] = 1.3; features[1, 2] = 1.4; features[1, 3] = 1.2;
features[1, 4] = 1.0; features[1, 5] = 1.3; features[1, 6] = 1.1; features[1, 7] = 1.2;
// Class 1: high-amplitude trend
features[2, 0] = 2.0; features[2, 1] = 2.5; features[2, 2] = 2.3; features[2, 3] = 2.8;
features[2, 4] = 3.0; features[2, 5] = 3.2; features[2, 6] = 3.5; features[2, 7] = 3.8;
features[3, 0] = 2.1; features[3, 1] = 2.4; features[3, 2] = 2.6; features[3, 3] = 2.9;
features[3, 4] = 3.1; features[3, 5] = 3.3; features[3, 6] = 3.4; features[3, 7] = 3.7;
var labels = new Vector<double>(new double[] { 0, 0, 1, 1 });
// Train: extract max and PPV features from random kernels and fit classifier
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(new RocketClassifier<double>(options))
.Build(features, labels);
// Predict class for new time series
var newSample = new Matrix<double>(1, 8);
newSample[0, 0] = 1.0; newSample[0, 1] = 1.1; newSample[0, 2] = 1.3; newSample[0, 3] = 1.2;
newSample[0, 4] = 1.0; newSample[0, 5] = 1.2; newSample[0, 6] = 1.1; newSample[0, 7] = 1.0;
var predictions = result.Predict(newSample);
// Result is available in the returned value
Constructors
| Constructor | Summary |
|---|---|
RocketClassifier(RocketOptions<T> options) |
Creates a new ROCKET classifier. |
Properties
| Property | Summary |
|---|---|
bool SupportsVariableLengths { get; } |
Gets whether this classifier supports variable-length sequences. |
int NumChannels { get; set; } |
Gets or sets the number of channels (variables) in the time series. |
int SequenceLength { get; set; } |
Gets or sets the expected sequence length. |
Methods
| Method | Summary |
|---|---|
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) |
|
Matrix<T> PredictSequenceProbabilities(Tensor<T> sequences) |
Predicts class probabilities for time series sequences. |
Vector<T> Predict(Matrix<T> input) |
Predicts class labels for feature matrix. |
Vector<T> PredictSequences(Tensor<T> sequences) |
Predicts class labels for time series sequences. |
void Train(Matrix<T> x, Vector<T> y) |
Trains the classifier on feature matrix (used after transform). |
void TrainOnSequences(Tensor<T> sequences, Vector<T> labels) |
Trains the ROCKET classifier on time series data. |