ExplainableBoostingClassifier<T>

Models & Types · AiDotNet.Classification.Boosting

Explainable Boosting Machine (EBM) for interpretable classification.

Inheritance: ClassifierBase<T> → ProbabilisticClassifierBase<T> → EnsembleClassifierBase<T> → ExplainableBoostingClassifier<T>

For Beginners

EBM is special because it gives you the best of both worlds:

  • High accuracy (comparable to gradient boosting and random forests)
  • Full interpretability (you can see exactly why each prediction was made)

How it works:

  1. For each feature, EBM learns a “shape function” that shows how that feature

affects the prediction

  1. The final prediction is simply the sum of all these shape functions plus

an intercept, passed through sigmoid for probability

  1. You can plot these shape functions to understand exactly how the model

uses each feature

For example, in predicting loan defaults:

  • The shape function for “income” might show higher income = lower risk
  • The shape function for “debt_ratio” might show higher ratio = higher risk
  • The prediction combines: intercept + f(income) + f(debt_ratio) + …

This additive structure makes EBM uniquely interpretable while still being accurate.

How It Works

EBM is a Generalized Additive Model (GAM) with boosting that provides glass-box interpretability while maintaining high accuracy. It learns smooth functions for each feature and optionally pairwise interactions.

Reference: Lou, Y., et al. “Intelligible Models for Healthcare: Predicting Pneumonia Risk and Hospital 30-day Readmission” (2012).

Example

// Create EBM classifier for interpretable predictions
var options = new ExplainableBoostingClassifierOptions<double>();
            
// 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 additive model with per-feature shape functions
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
    .ConfigureModel(new ExplainableBoostingClassifier<double>(options))
    .Build(features, labels);
            
// Predict with full interpretability (shape function contributions visible)
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
ExplainableBoostingClassifier(ExplainableBoostingClassifierOptions<T> options, IRegularization<T, Matrix<T>, Vector<T>> regularization) Initializes a new instance of ExplainableBoostingClassifier.

Properties

Property Summary
IReadOnlyDictionary<ValueTuple<int, int>, Matrix<T>> InteractionTerms { get; } Gets the interaction terms.
IReadOnlyList<Vector<T>> BinEdges { get; } Gets the bin edges for each feature.
IReadOnlyList<Vector<T>> ShapeFunctions { get; } Gets the shape functions for each feature.
T Intercept { get; } Gets the intercept (baseline log-odds).

Methods

Method Summary
Dictionary<string, T> ExplainPrediction(Vector<T> sample) Explains a single prediction by showing each feature’s contribution.
Matrix<T> PredictProbabilities(Matrix<T> input) Predicts class probabilities for input samples.
ModelMetadata<T> GetModelMetadata()
Vector<T> Predict(Matrix<T> input) Predicts class labels for input samples.
void Train(Matrix<T> x, Vector<T> y) Returns the model type identifier.