HoeffdingTreeClassifier<T>
Models & Types · AiDotNet.Classification.Online
Implements the Hoeffding Tree (Very Fast Decision Tree) for online classification.
Inheritance: ClassifierBase<T> → HoeffdingTreeClassifier<T>
Implements: IOnlineClassifier<T>
For Beginners
Hoeffding Tree is a decision tree that can be built incrementally from streaming data. It uses the Hoeffding bound to determine when enough samples have been seen to make a confident split decision.
How It Works
How it works:
- Start with a single leaf node
- As samples arrive, update statistics at each leaf
- When enough samples are seen, use Hoeffding bound to decide if the best split is significantly better
- If yes, split the leaf into internal node with two children
- Repeat for all leaves as new samples arrive
The Hoeffding bound: With probability (1 - δ), the true best attribute is within ε of the observed best, where ε = sqrt(R² * ln(1/δ) / (2n)) and n is the number of samples.
Advantages:
- Constant memory per node (bounded statistics)
- Processes each sample only once
- Converges to batch decision tree with enough samples
- Suitable for infinite data streams
Reference: Domingos & Hulten, “Mining High-Speed Data Streams” (2000)
Example
// Create Hoeffding tree for incremental stream classification
var options = new HoeffdingTreeOptions<double>();
// Prepare streaming data batch
var features = new Matrix<double>(new double[,] { { 1.0, 1.1 }, { 1.2, 0.9 }, { 0.8, 1.0 }, { 5.0, 5.1 }, { 5.2, 4.9 }, { 4.8, 5.0 } });
var labels = new Vector<double>(new double[] { 0, 0, 0, 1, 1, 1 });
// Train incrementally, splitting nodes when Hoeffding bound is satisfied
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(new HoeffdingTreeClassifier<double>(options))
.Build(features, labels);
// Predict class for new sample
var newSample = new Matrix<double>(new double[,] { { 1.1, 1.0 } });
var prediction = result.Predict(newSample);
// Result is available in the returned value
Constructors
| Constructor | Summary |
|---|---|
HoeffdingTreeClassifier(HoeffdingTreeOptions<T> options) |
Creates a new Hoeffding Tree classifier. |
Properties
| Property | Summary |
|---|---|
bool IsWarm { get; } |
Gets whether the model has seen at least one sample. |
long SamplesSeen { get; set; } |
Gets the total number of samples the model has seen. |
Methods
| Method | Summary |
|---|---|
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) |
Returns a fresh instance — tree structure cannot be reconstructed from flat parameters. |
ModelOptions GetOptions() |
|
Vector<T> Predict(Matrix<T> input) |
|
void PartialFit(Matrix<T> features, Vector<T> labels) |
Updates the model with a batch of training samples. |
void PartialFit(Vector<T> features, T label) |
Updates the model with a batch of training samples. |
void Train(Matrix<T> x, Vector<T> y) |