Skip to content
BIASED

Gradient boosting

Block 1 of 8~3 min

Fitting residuals

The topic Bagging and random forests ended with a limit. Averaging trees grown independently lowers the variance but keeps the bias of a single tree, so a forest needs deep trees and can do nothing about an error that all its trees share. Boosting builds the ensemble the other way round. The trees are small and grown one after another, and each new tree is fitted to what the current ensemble still gets wrong.

Start with squared loss and the best constant, F0=yˉF_0 = \bar y. Its errors on the training set are the residuals ri=yi−F0r_i = y_i - F_0. Fit a regression tree b1b_1 to the residuals by least squares: it predicts where the model is too low and where too high. Add it with a small factor, the learning rate η∈(0,1]\eta \in (0, 1]:

F1(x)=F0+η b1(x).F_1(x) = F_0 + \eta \, b_1(x).

Then fit b2b_2 to the new residuals yi−F1(xi)y_i - F_1(x_i), and so on. After MM stages the model is

FM(x)=F0+η∑m=1Mbm(x).F_M(x) = F_0 + \eta \sum_{m=1}^{M} b_m(x).

A toy version of the house-price task: four houses with x=1,2,3,4x = 1, 2, 3, 4 rooms and prices y=1,3,4,8y = 1, 3, 4, 8 (in hundreds of thousands). Take stumps, trees with one split, and η=0.5\eta = 0.5. Then F0=4F_0 = 4 and the residuals are −3,−1,0,4-3, -1, 0, 4. The best stump splits between 3 and 4 rooms and predicts −4/3-4/3 on the left and 44 on the right. Half of it moves the model to (3.333,3.333,3.333,6)(3.333, 3.333, 3.333, 6). Three stages by hand:

import numpy as np
from sklearn.tree import DecisionTreeRegressor
 
x = np.array([[1.0], [2.0], [3.0], [4.0]])
y = np.array([1.0, 3.0, 4.0, 8.0])
F = np.full(4, y.mean())                       # F_0 = 4
for m in range(1, 4):
    stump = DecisionTreeRegressor(max_depth=1).fit(x, y - F)
    F += 0.5 * stump.predict(x)                # eta = 0.5
    print(m, F.round(3), round(float(((y - F) ** 2).mean()), 3))
1 [3.333 3.333 3.333 6.   ] 2.5
2 [2.167 3.722 3.722 6.389] 1.139
3 [1.694 3.25  4.194 6.861] 0.47

The training MSE falls from 6.56.5 to 2.52.5, 1.1391.139 and 0.470.47. Each stump alone is a poor model, a single question. Their sum is not: the bias falls with every stage. That is the opposite of bagging, where strong trees are only averaged.

Answers are saved on the server and tied to this browser until you sign in.