Skip to main content

boosting.BoosterFit

A fitted Booster: means and joint predictive draws.

Usage

Source

boosting.BoosterFit(
    spec,
    names,
    model,
    boots,
    dispersion,
    base,
)

Attributes

model

The engine’s booster (lightgbm.Booster or xgboost.Booster).

base: float

The constant added to the offset so the trees start from the mean.

dispersion: float

1 for the Poisson; otherwise Pearson’s estimate on the training rows, sum w (y - mu)^2 / V(mu) / n (no degrees-of-freedom correction: trees have no fixed parameter count).

dispersion_fit
With dispersion_model=True, the dispersion booster and its starting log level; otherwise None.

Methods

Name Description
check_monotone() The partial dependence of the predictions on feature (a
contributions() Tree SHAP: each design column’s contribution to each row’s
predict() Fitted means for the rows of design (the alpha quantiles
predict_dispersion() Each row’s dispersion from the dispersion model, or the constant
predict_distribution() Joint draws across the rows, keyed row = 0, 1, ...: each row’s

check_monotone()

The partial dependence of the predictions on feature (a

Usage

Source

check_monotone(design, feature, grid=None, direction=None, tol=1e-09)

design column) over grid: the mean prediction over the rows of design with the column set to each value, and where it moves against direction (the fit’s monotone constraint by default). The engines enforce a constraint split by split, so this confirms it on the model as fitted.

Parameters
design: Design
feature: str
grid: list of float = None

Twenty quantiles of the column by default.

direction: (1, -1) = 1
tol: float = 1e-9
Relative tolerance on a step against the direction.
Returns
dict
grid, mean, direction, violations (indices i whose step from i - 1 goes against the direction) and monotone.

contributions()

Tree SHAP: each design column’s contribution to each row’s

Usage

Source

contributions(design)

prediction on the link scale, from the engine’s own path-dependent Tree SHAP (Lundberg, Erion and Lee; LightGBM’s pred_contrib, XGBoost’s pred_contribs), with no tree code here.

Parameters
design: Design
Same columns as the training design; its offset applies.
Returns
dict
names (the design’s columns), values (one list per row, one contribution per column) and bias (each row’s expected value plus its offset and the fit’s base), so that bias[i] + sum(values[i]) is the row’s link-scale prediction: the log of the mean for a log-link family.

predict()

Fitted means for the rows of design (the alpha quantiles

Usage

Source

predict(design)

for family="quantile").

Parameters
design: Design
Same columns as the training design; its offset applies.
Returns
list of float

predict_dispersion()

Each row’s dispersion from the dispersion model, or the constant

Usage

Source

predict_dispersion(design)

dispersion when the booster was fitted without one.

Parameters
design: Design
Returns
list of float

predict_distribution()

Joint draws across the rows, keyed row = 0, 1, ...: each row’s

Usage

Source

predict_distribution(design, n_sims, seed)

response from the family around its mean (process noise), with the means of one bootstrap refit per simulation when n_boot > 0 (parameter uncertainty).

Parameters
design: Design
n_sims: int
seed: int
Returns
PredictiveDistribution