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, . Its errors on the training set are the residuals . Fit a regression tree 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 :
Then fit to the new residuals , and so on. After stages the model is
A toy version of the house-price task: four houses with rooms and prices (in hundreds of thousands). Take stumps, trees with one split, and . Then and the residuals are . The best stump splits between 3 and 4 rooms and predicts on the left and on the right. Half of it moves the model to . 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.47The training MSE falls from to , and . 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.