TimeSeriesForestClassifier<T>

Models & Types · AiDotNet.Classification.TimeSeries

Implements the Time Series Forest classifier.

Inheritance: ClassifierBase<T> → TimeSeriesForestClassifier<T>

Implements: ITimeSeriesClassifier<T>

For Beginners

Time Series Forest builds an ensemble of decision trees, where each tree is trained on features extracted from a randomly selected interval of the time series. This approach captures patterns at different time scales and positions.

How It Works

How it works:

  • For each tree, randomly select an interval (start, end) from the time series
  • Extract summary features from that interval (mean, std, slope)
  • Train a decision tree on these interval features
  • Repeat for all trees in the ensemble
  • Predict by majority voting across all trees

Key features:

  • Captures local patterns at different positions in the sequence
  • Robust to noise through ensemble averaging
  • Interpretable through interval selection
  • Handles variable-length sequences naturally

Reference: Deng et al., “A Time Series Forest for Classification and Feature Extraction” (2013)

Example

// Create Time Series Forest with ensemble of interval-based decision trees
var options = new TimeSeriesForestOptions<double>();
            
// Prepare time series data: rows are samples, columns are time steps
var features = new Matrix<double>(4, 5);
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[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[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[3, 0] = 2.1; features[3, 1] = 2.4; features[3, 2] = 2.6; features[3, 3] = 2.9; features[3, 4] = 3.1;
var labels = new Vector<double>(new double[] { 0, 0, 1, 1 });
            
// Train: classify using mean, std, and slope features from random intervals
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
    .ConfigureModel(new TimeSeriesForestClassifier<double>(options))
    .Build(features, labels);
            
// Predict class for new time series
var newSample = new Matrix<double>(1, 5);
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;
var predictions = result.Predict(newSample);
// predictions[0] contains the predicted class

Constructors

Constructor Summary
TimeSeriesForestClassifier(TimeSeriesForestOptions<T> options) Creates a new Time Series Forest classifier.

Properties

Property Summary
bool SupportsVariableLengths { get; } Gets whether this classifier supports variable-length sequences.
int NumChannels { get; set; } Gets the number of channels (variables) in the time series.
int SequenceLength { get; set; } Gets 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.
ModelOptions GetOptions()
Vector<T> Predict(Matrix<T> input)
Vector<T> PredictSequences(Tensor<T> sequences) Predicts class labels for time series sequences: the class with the highest mean tree probability.
void Train(Matrix<T> x, Vector<T> y)
void TrainOnSequences(Tensor<T> sequences, Vector<T> labels) Trains the Time Series Forest on time series sequences.