Explainable Boosting Machine (EBM / GA2M): additive glassbox models.
An Explainable Boosting Machine learns an additive model of per-feature shape functions. Each feature is binned, and a boosting procedure learns a score for every bin, so the whole model is a lookup table that a human can read directly:
where f_j is a step function over the quantile bins of feature j and g is the identity (regression), the sigmoid (binary classification), or the softmax (multiclass). Because the model is additive, its predictions can be decomposed exactly into one contribution per feature via explain.
This module implements the GA1M (generalised additive model) form. Pairwise-interaction terms (the "GA2M" extension) are not yet included.
Classes
class algorithms.glassbox.ebm.ExplainableBoostingRegressor(Regressor, _BaseEBM)
Explainable Boosting Machine for regression (additive shape functions).
__init__( self, n_bins: int = 32, max_rounds: int = 100, learning_rate: float = 0.01, feature_names: Optional[List[str]] = None, )
Overview
-
Quantile-bin each feature into (up to)
n_binsbins - Initialize the intercept to the mean target and every bin score to zero
- For each boosting round, cycle over features and add the learning-rate
- Center each shape function and fold the offsets into the intercept
-
Predict as
intercept_ + sum_j shape_j(x_j)
Theory
The model is the additive expansion
where f_j is constant over each quantile bin of feature j. Training minimises squared error by gradient boosting: at each step the negative gradient y - \hat{y} is averaged per bin and added to the bin score, exactly the optimal leaf value for a squared-error stump.
Parameters
n_bins
max_rounds
learning_rate
feature_names
feature_0, feature_1, ....
Attributes
intercept_
shape_functions_
(n_bins, 1).
bin_edges_
n_bins_per_feature_
feature_importance_
n_features_
Notes
Complexity:
- Training: O(R \cdot m \cdot n) where R = max_rounds,
- Prediction: O(m) per sample (one bin lookup per feature).
- When you need a model a human can audit feature-by-feature
- When the signal is roughly additive (no strong interactions)
- When you want exact, per-feature prediction decompositions via
explainReferences
See Also
>>> from tuiml.algorithms.glassbox import ExplainableBoostingRegressor
>>> import numpy as np
>>> X = np.array([[0.], [1.], [2.], [3.], [4.], [5.], [6.], [7.]])
>>> y = 2.0 * X.ravel() + 1.0
>>> reg = ExplainableBoostingRegressor(n_bins=8, max_rounds=200, learning_rate=0.1)
>>> _ = reg.fit(X, y)
>>> np.allclose(reg.predict(np.array([[2.0], [6.0]])), [5.0, 13.0], atol=1e-3)
True
>>> np.allclose(reg.predict(X), reg.intercept_[0] + reg.explain(X).sum(axis=1), atol=1e-12)
True
Methods
__repr__
(self) -> str
class algorithms.glassbox.ebm.ExplainableBoostingClassifier(Classifier, _BaseEBM)
Explainable Boosting Machine for classification (additive shape functions).
__init__( self, n_bins: int = 32, max_rounds: int = 100, learning_rate: float = 0.01, feature_names: Optional[List[str]] = None, )
Overview
-
Quantile-bin each feature into (up to)
n_binsbins - Initialize an intercept and zero bin scores
- For each boosting round, cycle over features and add the learning-rate
- Center each shape function and fold offsets into the intercept
- Map the additive score through the sigmoid (binary) or softmax
Theory
The additive score is
For binary classification the probability is p = \sigma(s) with the logistic function, and the negative gradient used for boosting is y - p. For multiclass, a score vector per class is used and the negative gradient is the one-hot target minus the softmax output.
Parameters
n_bins
max_rounds
learning_rate
feature_names
Attributes
intercept_
shape_functions_
(n_bins, 1) (binary) or (n_bins, n_classes) (multiclass).
bin_edges_
classes_
feature_importance_
n_features_
Notes
Complexity:
- Training: O(R \cdot m \cdot n \cdot K) where R =
- Prediction: O(m \cdot K) per sample.
- When a human must be able to audit how each feature drives the score
- When the signal is roughly additive
- When you want exact per-feature log-odds contributions via
explainReferences
See Also
>>> from tuiml.algorithms.glassbox import ExplainableBoostingClassifier
>>> import numpy as np
>>> X = np.array([[0.], [1.], [2.], [3.], [4.], [5.], [6.], [7.]])
>>> y = np.array([0, 0, 0, 0, 1, 1, 1, 1])
>>> clf = ExplainableBoostingClassifier(n_bins=8, max_rounds=200, learning_rate=0.5)
>>> _ = clf.fit(X, y)
>>> clf.predict(np.array([[2.0], [6.0]])).tolist()
[0, 1]
>>> bool(clf.predict_proba(np.array([[6.0]]))[0, 1] > 0.5)
True
Methods
__repr__
(self) -> str