Skip to content
AI360XpertBeta
Core ML

Visual explainer

Gradient Boosting

Fit trees to loss-dependent corrections and add their scaled outputs. Work two squared-loss rounds on four observations, then see why constant leaves cannot extrapolate.

The mean prediction of 5 leaves signed gaps to four observed targets.
The mean prediction of 5 leaves signed gaps to four observed targets.

Gradient boosting adds trees that correct the current ensemble according to a chosen loss. With half squared loss, the corrections are ordinary residuals: observed target minus current prediction. Our synthetic, unitless training observations are (1,2), (2,4), (3,6), (4,8). Target rings share a feature axis; the starting prediction is the target mean, F0=(2+4+6+8)/4=5F_0=(2+4+6+8)/4=5, shown by the horizontal line. Dashed segments expose the gaps.

Give Corrections a Sign

Residuals tell the next tree both the direction and size of each correction.
Residuals tell the next tree both the direction and size of each correction.

The target-minus-prediction residuals are −3, −1, +1, +3. Downward bars require a lower prediction, upward bars a higher one. This residual view uses 30 drawing units per residual unit, with zero in the middle; it is a different vertical quantity from the response plot's 25 drawing units per target unit.

For ℓ(y,F)=12(y−F)2\ell(y,F)=\tfrac12(y-F)^2, the negative derivative with respect to prediction is y−Fy-F. The gradient boosting formulation fits new trees to loss-dependent negative gradients. This equality with ordinary residuals depends on the loss.

Fit a Residual Tree

A stump splits the residuals at 2.5 and predicts the mean in each leaf.
A stump splits the residuals at 2.5 and predicts the mean in each leaf.

Compare midpoint cuts 1.5, 2.5, and 3.5. Cut 2.5 groups residuals [−3,−1] and [1,3], whose means are −2 and +2. The mint step is the fitted tree h1h_1; rings are the residual targets, all on the same signed scale. Its squared residual-fit error is 1+1+1+1=41+1+1+1=4, versus 8 at either alternative cut. A tree leaf gives one shared correction, so it does not copy every residual exactly.

Add a Scaled Correction

Adding half the first tree moves the baseline to predictions 4 and 6.
Adding half the first tree moves the baseline to predictions 4 and 6.

Return to the original response scale. With learning rate η=0.5\eta=0.5, update F1=F0+ηh1F_1=F_0+\eta h_1. The left leaf moves 5+0.5(−2)=45+0.5(-2)=4; the right moves 5+0.5(2)=65+0.5(2)=6. Predictions become 4, 4, 6, 6. The arrows move one response unit; the dotted line retains the old prediction. Targets at feature values 2 and 3 now lie on the fit, but the extreme observations still have residuals −2 and +2.

Measure the Training Error

Training mean squared error falls from 5 to 2 to 1 over two fitted corrections.
Training mean squared error falls from 5 to 2 to 1 over two fitted corrections.

These bars report mean squared error, without the half factor used to define the fitting loss: MSE⁡=14∑i(yi−F(xi))2\operatorname{MSE}=\tfrac14\sum_i(y_i-F(x_i))^2. The baseline has (9+1+1+9)/4=5(9+1+1+9)/4=5. After the first update it has (4+0+0+4)/4=2(4+0+0+4)/4=2.

For the second correction, fit the new residuals [−2,0,0,2]. A cut at 1.5 gives leaf means −2 and 2/3. Adding half yields 3, 13/3, 19/3, 19/3. Its squared errors are 1,1/9,1/9,25/91,1/9,1/9,25/9, averaging to 1. Scene 7 pictures that refit. The bar scale is 40 drawing units per MSE unit. This is a computed training trace; no held-out curve or optimal round count is available.

Compare the First Step

A full first step has lower training error than a half step on this fixture.
A full first step has lower training error than a half step on this fixture.

Both panels use identical targets and scales, compressed horizontally to place the comparison side by side. The first tree is fixed. Rate 0.5 produces [4,4,6,6], with MSE 2. Rate 1 produces [3,3,7,7], with MSE 1. The full step does not overshoot a target range or necessarily destabilize this fit. Smaller rates often trade more rounds for different generalization behaviour; they are not automatically better on training error. Choose rate and round count together using representative held-out evaluation. Future trees must be refitted for each rate rather than reusing a trajectory learned under another rate.

Recompute Before Refitting

The second tree refits the new residuals with a different split at 1.5.
The second tree refits the new residuals with a different split at 1.5.

Continue the half-rate run. Rings now show −2,0,0,+2, not the original residuals. Cuts 1.5 and 3.5 tie with squared residual-fit error 8/38/3; our tie rule chooses the smaller threshold. Cut 1.5 leaves −2 alone and groups [0,0,2] at mean 2/3. The signed step shows those outputs. Cut 2.5 would cost 4, so simply reusing the first split is worse here.

The updated predictor is F2(x)=5+0.5h1(x)+0.5h2(x)F_2(x)=5+0.5h_1(x)+0.5h_2(x). The new tree corrects the current ensemble, not just the immediately previous tree. For feature 4, the latest correction is only 1/3 even though its residual is 2, because that leaf also contains two zero residuals.

Sum at Inference Time

Prediction at 3.2 adds the baseline and both scaled tree contributions.
Prediction at 3.2 adds the baseline and both scaled tree contributions.

A fresh feature value 3.2 lies in the right leaf of both trees. The floating bars show baseline 5, first contribution 0.5(2)=10.5(2)=1, and second contribution 0.5(2/3)=1/30.5(2/3)=1/3. Their cumulative height is 19/3≈6.33319/3\approx6.333. The small last bar retains its honest one-third height; the label makes its value explicit. No new tree is fitted for this query, and no observed target is supplied, so this is an inference check rather than evidence of test accuracy.

Change the Loss Target

Absolute loss uses residual signs where half squared loss uses residual magnitudes.
Absolute loss uses residual signs where half squared loss uses residual magnitudes.

Both panels return to the initial prediction 5 and use the same 30-units-per-gradient scale. Half squared loss gives targets [−3,−1,+1,+3]. Absolute loss gives negative subgradient targets [−1,−1,+1,+1] at these nonzero residuals: a large miss does not create a larger gradient magnitude. This compares the fit targets, not two completed models.

For absolute loss, leaf outputs also need loss-specific optimization; fitting a tree to signs alone does not mean the final correction in every leaf is exactly ±1. The loss-function discussion describes this adjustment. Ordinary residual fitting cannot be assumed for every boosting objective.

Where It Breaks

Constant tree leaves predict the same plateau outside the training range and miss a rising target.
Constant tree leaves predict the same plateau outside the training range and miss a rising target.

Keep the two half-rate trees. This wider view uses 75 drawing units per feature unit and 20 per response unit. The dashed divider is the largest training feature, 4. Both trees route any feature above 4 into the same right leaves; their sum stays 19/319/3 at feature 6. If the underlying relation continues as y=2xy=2x, the target at 6 is 12, shown by the amber ring. The cross is the flat model prediction, with a gap of 12−19/3=17/312-19/3=17/3.

The continued relation is an explicit illustrative assumption, not something proven by four training points. A sum of finite trees with constant leaves remains piecewise constant: adding trees cannot make these far-right leaves extrapolate a rising slope. This boundary applies to constant-leaf trees, not every possible gradient-boosting base learner. Use data covering the intended prediction range or a model with suitable extrapolation assumptions.

The Quick Version

  • Start squared-loss fitting from the target mean.
  • Residuals carry direction and magnitude.
  • Leaves share corrections among their observations.
  • Scale each tree before adding its output.
  • Measure training loss using a consistent definition.
  • Smaller learning rates are not automatically better.
  • Refit against the entire current ensemble.
  • Inference sums the baseline and learned contributions.
  • Loss choice changes gradient targets and leaf updates.
  • Constant tree leaves cannot extrapolate a rising slope.