HistGradientBoostingClassifier<T>

Models & Types · AiDotNet.Classification.Boosting

Histogram-based Gradient Boosting Classifier.

Inheritance: ClassifierBase<T> → HistGradientBoostingClassifier<T>

For Beginners

This is a fast gradient boosting implementation that uses histograms to speed up the tree-building process. It’s similar to LightGBM and scikit-learn’s HistGradientBoostingClassifier.

How It Works

How it works: Instead of evaluating all possible split points, this algorithm:

  • Bins continuous features into a fixed number of buckets (histograms)
  • Builds trees by evaluating splits only at bin boundaries
  • Uses gradient boosting to iteratively improve predictions

Key advantages:

  • Speed: Much faster than traditional gradient boosting on large datasets
  • Memory: Uses less memory due to binning
  • Missing values: Please impute before training (missing-value handling is not built in)
  • Scalability: Scales well to millions of samples

When to use:

  • When you have a large dataset (thousands to millions of samples)
  • When you need fast training without sacrificing much accuracy
  • For tabular data classification problems

References:

  • Ke, G. et al. (2017). “LightGBM: A Highly Efficient Gradient Boosting Decision Tree”
  • Scikit-learn HistGradientBoostingClassifier implementation

Example

// Prepare training data: 6 samples with 2 features
var features = new Matrix<double>(6, 2);
features[0, 0] = 1.0; features[0, 1] = 1.1;
features[1, 0] = 1.2; features[1, 1] = 0.9;
features[2, 0] = 0.8; features[2, 1] = 1.0;
features[3, 0] = 5.0; features[3, 1] = 5.1;
features[4, 0] = 5.2; features[4, 1] = 4.9;
features[5, 0] = 4.8; features[5, 1] = 5.0;
var labels = new Vector<double>(new double[] { 0, 0, 0, 1, 1, 1 });
            
// Train through the facade: the builder configures the model, runs the training pipeline and
// returns a result to predict on.
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
    .ConfigureModel(new HistGradientBoostingClassifier<double>(
        maxBins: 256, maxDepth: 6, nEstimators: 100, learningRate: 0.1))
    .Build(features, labels);
            
// Predict class for new sample
var newSample = new Matrix<double>(1, 2);
newSample[0, 0] = 1.1; newSample[0, 1] = 1.0;
var prediction = result.Predict(newSample);
// Result is available in the returned value

Constructors

Constructor Summary
HistGradientBoostingClassifier(int maxBins, int maxDepth, int nEstimators, double learningRate, int minSamplesLeaf, double l2Regularization, int? seed) Initializes a new instance of HistGradientBoostingClassifier.

Properties

Property Summary
int NJobs { get; set; } Gets or sets the number of threads that build each tree: a positive count, or negative to count back from the processor count (-1, the default, uses every processor, as scikit-learn’s HistGradientBoostingClassifier does).

Methods

Method Summary
Dictionary<string, T> GetFeatureImportance() Gets feature importance based on total gain reduction.
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) Creates a new instance with the specified parameters.
Vector<T> Predict(Matrix<T> input) Predicts class labels for the given input data.
void Train(Matrix<T> x, Vector<T> y) Gets the model type.