Gradient Boosting: Does a Stronger Model Win?

A single small decision tree is easy to read but makes many mistakes, and a single large tree learns its training rows too closely. Gradient boosting takes a different path. It builds many small trees one after another, each one correcting what the trees before it still get wrong, and adds their answers together. This page explains how that works and which settings decide how closely such a model fits its training rows. It then shows how to judge fairly whether this more powerful kind of model is worth choosing over a simpler one when their scores come out close.

Many small trees, added one at a time

Picture a subscription service that wants to predict which customers will leave. Gradient boosting does not try to find one perfect tree. It starts from a plain first guess and then improves that guess in small steps.

  1. Start from one number for everyone. Before any tree exists, every customer gets the same score: the one that matches the share of customers who left in the training rows. If a quarter of them left, every customer starts at a probability of 0.25.
  2. Look at what is still wrong. For a customer who left, 0.25 is far too low. For a customer who stayed, it is a little too high. These differences are the errors the model still makes.
  3. Fit one small tree to those errors. The new tree asks a few yes-or-no questions about the features, chosen so that its leaves push each customer's score in the direction of their error: up for the groups that mostly left, down for the groups that mostly stayed.
  4. Add a small part of that tree to the score, then go back to step 2 with the new, slightly better scores.

Each round adds one tree, and every tree is fitted to the errors left over by all the trees before it. That is what boosting means: the trees are built in sequence, and each one exists to correct its predecessors. The name gradient boosting comes from the precise way those errors are measured, which you do not need in order to use or reason about the model.

  • Current scores one per row
  • What is still wrong score vs real answer
  • Fit a small tree to those errors
  • Add a small part of it scores move closer
  • Current scores to What is still wrong
  • What is still wrong to Fit a small tree
  • Fit a small tree to Add a small part of it
  • Add a small part of it to Current scores

To predict for a new customer, the model runs that customer through every tree, adds up the numbers the trees give. It then squeezes the total into a probability between 0 and 1, with the same S-shaped function that logistic regression uses on its weighted sum.

Each tree outputs a number to be added, not a vote of yes or no. Trees that output numbers are called regression trees, so the trees inside a boosting classifier are regression trees, even though the final answer is a yes or a no. For a yes-or-no question there is exactly one tree per round, so a model with 100 rounds holds 100 trees.

The chart shows the idea for two made-up customers. Both start at the same probability. As trees are added, the customer who left is pushed up and the customer who stayed is pushed down, quickly at first and then more slowly, because less and less is still wrong.

Predicted probability of leaving, as trees are added (made-up example)

probability of leaving against trees added

  • customer who left
  • customer who stayed

True or false?

A boosting model trains its trees independently of each other and averages their answers.

False. Each tree is fitted after the ones before it, to the errors they still make, and the answers are added up. Training trees independently and averaging them is a different family of methods, such as random forests.

Before the first tree is added, a boosting classifier gives every row the same prediction.

True. It starts from one constant guess that matches the share of each answer in the training rows. Every tree after that moves the rows apart.

The trees inside a gradient boosting classifier each vote yes or no, and the majority wins.

False. Each tree gives a number that is added to the score, so they are regression trees. Only the final sum is turned into a probability.

Why the trees are kept small

It may seem odd to build a strong model out of weak parts. A tree of depth 1, often called a stump, asks a single question and has two leaves. A tree of depth 3 asks at most three questions along any path and has at most 8 leaves. On its own, such a tree is far too simple to predict well: it underfits.

Boosting works best with exactly these weak trees. Each one only has to capture a little of what is left, so it does not need to be large, and a small tree cannot memorise individual rows. The detail comes from adding many of them: a hundred small corrections, each aimed at a different leftover error, can trace a pattern that no single small tree could. A large tree in each round would leave the next trees little to correct and would carry the noise of the training rows straight into the sum.

Small trees also limit how features can combine. A tree of depth 1 judges one feature at a time. A tree of depth 2 can say "a short contract and a high monthly charge", combining two features in one leaf. In general, a tree of depth h can capture combinations of up to h features. This is something a weighted sum, which adds up each feature's push separately, cannot do on its own.

Tree depth and size
max_depthLeaves (at most)Features combined in one leaf
12up to 1
24up to 2
3 (default)8up to 3
532up to 5

The three settings that decide how closely it fits

Three hyperparameters, chosen before training, control how far a boosting model goes in learning its training rows. In scikit-learn the model is GradientBoostingClassifier from sklearn.ensemble, and it follows the same fit and predict pattern as every other model.

from sklearn.ensemble import GradientBoostingClassifier

model = GradientBoostingClassifier(
    learning_rate=0.1,  # how much each tree may contribute
    n_estimators=100,   # how many trees are added
    max_depth=3,        # how large each tree may grow
    random_state=0,     # same trees on every run
)
model.fit(X_train, y_train)
print(model.predict_proba(X_valid)[:5])

The values written here are the defaults, so GradientBoostingClassifier(random_state=0) builds the same model. The seed matters even though nothing obvious is random: the model looks at the features in a random order at each split, and when two splits are equally good, the order decides which one is kept.

  • learning_rate scales each tree before it is added. At 0.1, every tree moves the scores by only a tenth of what it found. Small steps make each tree's mistakes matter less, so a smaller value usually generalizes better, but it needs more trees to get as far.
  • n_estimators is the number of trees, one per round. More trees keep lowering the error on the training rows. Past some point they start correcting what is only noise in those rows, and the validation score stops improving or slips. This model does not stop on its own: it always builds every tree you ask for unless you turn on early stopping with n_iter_no_change.
  • max_depth limits each tree. Deeper trees fit each round's errors more closely and combine more features, which also means they overfit sooner. The default of 3 is already small. A single DecisionTreeClassifier, by contrast, grows without a limit by default.

scikit-learn also has HistGradientBoostingClassifier, a faster version of the same method that first sorts each feature's values into a small number of bins. It is much faster on large tables, from about ten thousand rows. Its defaults differ in two ways that matter here. It names the tree count max_iter (100 by default), and it limits each tree by its number of leaves, max_leaf_nodes=31, rather than by its depth, which has no limit (max_depth=None). So its default trees, with up to 31 leaves each, are much larger than trees of depth 3, and setting max_depth, for example to 2, makes them small.

The first two settings work as a pair. Halving learning_rate while keeping n_estimators fixed means every tree moves the scores only half as far, so the same number of trees leaves the model further from a good fit, not better. The usual approach is a small learning rate, such as 0.1 or lower, with enough trees for it to reach its best validation score. You choose them as you would any hyperparameter: try a few values under cross-validation and keep the simpler one when the scores tie.

Which way each setting pushes the fit
SettingDefaultFits training rows more closely whenFits them less closely when
learning_rate0.1it is largerit is smaller
n_estimators100there are more treesthere are fewer trees
max_depth3trees are deepertrees are shallower

Because the trees come one after another, a fitted model can show its predictions after the first tree, the first two, and so on, through staged_predict. Scoring those stages on training rows and on validation rows shows overfitting as it happens: the training score keeps climbing while the validation score levels off and then drifts down. The chart has that shape; its numbers are made up.

Accuracy after each number of trees (shape only, made-up numbers)

accuracy against trees added

  • training rows
  • validation rows

True or false?

Lowering learning_rate from 0.1 to 0.01 while keeping 100 trees makes the model better.

False. Each tree now moves the scores ten times less, so 100 trees get much less far. A smaller learning rate needs more trees to reach the same fit; the two are chosen together.

GradientBoostingClassifier keeps adding trees until it reaches n_estimators, even after the validation score stops improving.

True. Early stopping is off by default. It builds every tree you ask for unless you set n_iter_no_change.

With max_depth=1, each tree in the model can combine two features in one leaf.

False. A tree of depth 1 asks a single question about one feature. Combining two features in one leaf takes at least depth 2.

Comparing it fairly with simpler models

A comparison between two kinds of model only means something when nothing except the model differs. Both are trained and scored on the same rows, cut into the same folds, with the same preparation, and judged with the same score. The test rows stay untouched, because they are kept for one final measurement of the model you end up choosing.

The code below scores a logistic regression and a gradient boosting model with the same five stratified folds. Here X and y stand for the training rows, already turned into numbers. The scaler sits in a pipeline with the logistic regression so that it is learned again from the training folds of each round. The boosting model gets no scaler: its trees ask yes-or-no questions about one feature at a time, and those split the rows the same way whatever the scale, so scaling would change nothing for it. Both models still see the same columns.

from sklearn.ensemble import GradientBoostingClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import StratifiedKFold, cross_val_score
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

folds = StratifiedKFold(n_splits=5, shuffle=True, random_state=0)

models = {
    "logistic regression": make_pipeline(
        StandardScaler(), LogisticRegression(C=1.0)
    ),
    "gradient boosting": GradientBoostingClassifier(random_state=0),
}

for name, model in models.items():
    scores = cross_val_score(model, X, y, cv=folds, scoring="accuracy")
    print(f"{name}: mean {scores.mean():.3f}, spread {scores.std():.3f}")

Passing the same folds object to both calls is what makes the comparison fair: with its fixed seed, every model is trained and scored on exactly the same five splits. The loop prints, for each model, the mean of its fold scores as the estimate and their standard deviation as the spread, the uncertainty of that estimate.

When the scores are close

Gradient boosting is a strong default for tables of data, and it is easy to expect it to win every time. It does not. Its extra power lies in combining features and following shapes that a weighted sum cannot. When the answer mostly depends on each feature pushing the probability up or down on its own, a logistic regression already captures that, and the many trees have little left to add. Their scores then land close together, and either one may come out slightly ahead.

So the first question is whether a difference is real. The fold scores below are made up to show a typical case: the two means differ by less than the spread of either model's folds, and the boxes overlap almost entirely. A different set of folds could just as well put the other model in front. A difference that small is no evidence that one model is better.

Accuracy on five folds (made-up example)

accuracy

  • logistic regression
  • gradient boosting

When the difference sits inside the spread, the scores cannot decide, so other qualities do. This follows the same rule as choosing a hyperparameter: when scores tie, keep the simpler option.

What else separates two models with the same score
QualityLogistic regressionGradient boosting
How it predictsone weighted sum of the featuresthe sum of many small trees
Reading itone weight per feature, with a directionno single tree is the rule
Trainingone set of weightstrees built one after another
Settings to choosemainly Clearning_rate, n_estimators, max_depth

Each line of that table has a practical cost. A model that people can read is one they can check, question and trust: the weights of a logistic regression say, feature by feature, which way it pushes the prediction, while a boosting model's reasons are spread across a hundred trees. A model that trains quickly is cheaper to retrain and to test again, and a model with fewer settings has fewer choices that could have been tuned to luck. If boosting had scored clearly higher, beyond the spread, its gain might be worth those costs. When it does not, the simpler model is the better choice.

True or false?

Gradient boosting usually scores well on tables of data, so it will beat logistic regression on any table.

False. Being strong in general is no promise for a particular dataset. When the pattern is mostly separate pushes from each feature, a weighted sum already captures it and the scores come out close.

Two models with mean accuracies of 0.801 and 0.806 and a fold spread of about 0.01 should be treated as tied.

True. The gap of 0.005 is half the spread, so another set of folds could reverse the order. The choice then rests on simplicity, speed and how easy the model is to explain.

To decide between two close models, it is fine to score both once on the test rows and keep the higher one.

False. Choosing with the test rows turns them into one more validation set, and their score is no longer an honest estimate. Compare with validation rows or cross-validation, and keep the test rows for the final measurement.