Method · Statistics Library

Gradient boosting (boosted trees)

Gradient boosting builds many small decision trees one after another, each one correcting the errors the ensemble so far still makes, producing one of the most accurate off-the-shelf predictors for tabular data at the cost of a readable equation.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

Instead of building one big, complicated tree, gradient boosting builds many SMALL, weak trees in sequence. The first tree makes a rough guess; the second tree is trained specifically to fix the first tree's mistakes; the third fixes what is still wrong after the first two; and so on. The final prediction is just the sum of all these small corrections. This 'learn slowly, in tiny steps' strategy tends to generalize to new data better than trying to get everything right in one big leap.

Three dials control how this plays out: how many trees to build, how big a correction each tree is allowed to make (the learning rate), and how deep each individual tree is allowed to be. Crucially, unlike some other tree ensembles, boosting CAN overfit if you build too many trees or let each correction be too large: it will keep chasing smaller and smaller quirks in the training data until it starts fitting pure noise. The only way to know you have gone too far is to watch cross-validated performance, not training performance, since training performance keeps looking better and better even as the model quietly gets worse on new data.

As with other tree ensembles, feature importance here tells you what the model LEANS ON to make predictions, never what CAUSES the outcome in the real world, and this card takes a specific stance on how to measure that leaning honestly, described below.

Gradient boosting builds boosted trees, also called gradient boosted machines: many small trees added one after another, each correcting the errors of those before it.

Practitioner explanation

KernelStats uses scikit-learn's histogram-based gradient boosting (HistGradientBoosting*), which buckets each numeric predictor into at most 256 bins before searching for splits, the same trick behind LightGBM's speed, with essentially no accuracy cost. Categorical predictors are one-hot encoded, with the mapping stored on the card so exported code reproduces it exactly. Headline metrics are always k-fold cross-validated, with in-sample numbers shown only to demonstrate optimism (on the shipped penguins demo the model reaches 100% in-sample while honest CV accuracy is ~96.8%), and an explicit train-vs-CV gap check on the Assumptions tab flags a large gap automatically rather than leaving it for the analyst to notice by eye.

This card reports ONLY permutation importance: HistGradientBoosting has no built-in impurity/Gini importance to fall back on, which the product frames as a genuine advantage rather than a limitation, since impurity importance is known to be biased toward high-cardinality features (Strobl et al. 2007) while permutation importance is not. As with the decision tree and random forest cards, permutation importance is computed OUT OF SAMPLE (inside each CV fold, refit on the training part, permute on the held-out part, average across folds) specifically because permuting on the SAME rows the ensemble already fit to its own residuals would measure memorization, not genuine predictive usefulness; the training-set version is kept available separately for comparison but is never the headline ranking.

Classification models are checked for calibration via a cross-validated calibration curve and the Brier score: boosting directly optimizes log-loss, which TENDS to produce well-calibrated probabilities, but the product states plainly that 'tends to' is not 'always', especially with a large learning rate or too many rounds, and directs the analyst to actually check the curve rather than assume calibration follows automatically from the optimization objective. When a linear or logistic regression model reaches a comparable cross-validated score, the Learn More content explicitly recommends preferring the simpler model for its coefficients, confidence intervals, and p-values; boosting's added complexity is framed as something that must earn its keep with a real accuracy gap, not something to reach for by default.

When to use it

Consider it when

Predictive accuracy on tabular data matters more than an interpretable equation, the relationship between predictors and outcome may be non-linear with interactions, and a moderate-to-large dataset is available (each tree leaf needs a minimum row count by default, so very small datasets can collapse to a near-constant model).

Use caution when

A dataset with only a few dozen rows (leaves may fail to split meaningfully), a case where an interpretable coefficient-based model (linear/logistic regression) achieves comparable cross-validated performance, or when a predictor might secretly encode the outcome (an ID column, a downstream measurement): boosting will find and exploit that leakage, producing a near-perfect but meaningless cross-validated score that deserves suspicion rather than celebration.

Formulas and symbols

Boosted ensemble prediction

f^(x)=F0+∑m=1Mλ hm(x)\hat f(x) = F_0 + \sum_{m=1}^{M} \lambda\, h_m(x)

F_0 the starting prediction (the mean, or the class log-odds baseline); h_m a shallow tree fit to the gradient of the loss (the residuals, for squared error) of the ensemble so far; lambda (learning_rate) shrinks each tree's contribution so no single tree dominates.

Cross-validated performance

CV accuracy / RMSE=average over held-out folds\text{CV accuracy / RMSE} = \text{average over held-out folds}

Every row is scored by a model that never saw it during that fold's fit; the headline metric, always reported alongside (never replaced by) the in-sample number.

Brier score

Brier=1n∑i(pi−yi)2\text{Brier} = \dfrac{1}{n}\sum_i (p_i - y_i)^2

p_i the cross-validated predicted probability, y_i the actual 0/1 outcome; 0 is a perfect score, folding accuracy and calibration into one number.

Assumptions and checks

  • Gradient boosting can fit its own training data almost perfectly given enough rounds, so in-sample accuracy or RMSE substantially overstates how well the model will perform on new data.

    In KernelStats: Checked directly: every headline metric is k-fold cross-validated, with the train-vs-cross-validated performance gap reported as its own 'overfitting check' row.

  • A learning rate and round count that are too small together (a small 'learning budget') can leave the ensemble under-fit before training stops, while a leaf-size setting too large relative to the sample can make trees unable to split at all, degenerating toward a constant prediction.

    In KernelStats: Checked directly: the card reports learning_rate times n_estimators as the 'learning budget' and rows-per-leaf-size as their own checks, each flagged when too low.

  • With a severely imbalanced classification target, high overall accuracy can be achieved by mostly predicting the majority class, understating how useful the model actually is for the minority class.

    In KernelStats: Checked directly for classification: the card reports the smallest class's share of rows and flags it below 10%.

Alternatives

  • Decision Tree (CART). Interpretability (a single readable flowchart) matters more than the last few points of predictive accuracy.
  • Logistic Regression. A linear/logistic model reaches a comparable cross-validated score: prefer it for its coefficients, confidence intervals, and p-values at negligible accuracy cost.

Worked example

Scenario

Predicting penguin species from bill length, bill depth, flipper length and body mass with gradient boosting (defaults: depth 3, 100 rounds, learning rate 0.1, 5-fold CV, seed 42).

Result

In-sample accuracy = 100%, cross-validated accuracy = 96.8%; out-of-sample permutation importance ranks bill length and bill depth as the top two predictors.

Interpretation

The perfect in-sample score is the expected symptom of a flexible model fitting its own training rows closely, not evidence of a flawless model; the honest number to report and act on is the 96.8% cross-validated accuracy, and the out-of-sample importance ranking is the one to trust over the potentially inflated training-set version.

Dataset: penguins.csv

Common misconceptions

Misconception

Building more boosting rounds always improves the model, since more corrections mean a better fit.

Correction

Unlike a random forest, gradient boosting CAN overfit as the number of rounds grows: it keeps chasing residuals until it starts fitting noise specific to the training data. The training score keeps improving with more rounds even as the cross-validated score gets worse; only the cross-validated score, not the training score, reveals when to stop.

Misconception

A near-perfect cross-validated score is always good news.

Correction

A suspiciously high cross-validated score is often a symptom of DATA LEAKAGE: a predictor that secretly encodes the outcome (an ID field, a measurement taken after the outcome occurred). Because boosting is very good at finding and exploiting any signal available to it, an implausibly perfect result deserves scrutiny of the predictor set, not celebration.

Read more: Misconception: a model's training-set accuracy is its real-world performance

References

  1. An Introduction to Statistical Learning with Applications in R (2nd ed.), Chapter 8, James, G., Witten, D., Hastie, T. and Tibshirani, R. (2021).
  2. Verification of forecasts expressed in terms of probability, Brier, G. W. (1950), Monthly Weather Review, 78(1), 1-3.