Why Fit a Learner to Residuals?
In gradient boosting, each new learner is meant to improve the current predictor in a direction that reduces the chosen loss. For squared-error loss, that direction has a particularly direct interpretation: at each training observation, it is the difference between the observed response and the current fitted value. Those differences are the residuals. Least-squares boosting turns this observation into a practical procedure: calculate residuals, fit a learner to them, and add the fitted learner to the current prediction.
The word “pseudo” emphasizes that this is an instance of a more general gradient-based construction. For squared-error loss, however, the pseudo-residuals are exactly the ordinary response residuals. The key is to calculate the gradient with respect to the current fitted value, not with respect to the original response.
Definition and Gradient Calculation
Let the training data be \((x_i,y_i)\), \(i=1,\ldots,n\), and let \(F\) be the current prediction function. Use the half-squared-error loss for one observation,
The factor \(1/2\) simplifies the derivative. The empirical risk is the average of these losses, \(R(F)=n^{-1}\sum_{i=1}^n L(y_i,F(x_i))\). The pseudo-residual at observation \(i\) is the negative derivative of its individual loss with respect to its current fitted value.
The scaling in the empirical risk should not be confused with the derivative of an individual loss. For one observation, the derivative is \(-[y_i-F(x_i)]\). By contrast, differentiating the empirical risk with respect to the single fitted-value coordinate \(F(x_i)\) gives \(-[y_i-F(x_i)]/n\), because that observation’s loss is weighted by \(1/n\). These derivatives differ by the same positive factor for every observation, so they give the same direction of descent.
Worked Example: Checking the Derivative and Its Scale
Suppose \(n=4\), and for one observation the response is \(y_i=5\) while the current fitted value is \(F(x_i)=2\). Its residual is \(r_i=5-2=3\).
For the individual loss, \(L(y_i,z)=\frac12(y_i-z)^2\), so \(\frac{\partial L(y_i,z)}{\partial z}=-(y_i-z)\). At \(z=2\), this derivative is \(-3\), and the negative derivative is \(3\).
For the empirical risk \(R(F)=\frac{1}{n}\sum_j \frac12\{y_j-F(x_j)\}^2\), the derivative with respect to \(F(x_i)\) is \(-\frac14(5-2)=-\frac34\). Its negative is \(3/4\). Thus the individual-loss pseudo-residual is \(3\), whereas the negative empirical-risk coordinate derivative is \(3/4\). The factor \(1/4\) is due to averaging over the four observations; it does not belong in the derivative of the individual loss.
The Least-Squares Boosting Step
A learner is fitted by least squares to the pseudo-residuals, not to the original \(y_i\) values. If the available learner class is \(\mathcal H\), the fitting step seeks a function \(h\in\mathcal H\) that minimizes \(\sum_i\{r_i-h(x_i)\}^2\). In practice, \(\mathcal H\) might consist of constant functions or regression trees of a chosen form. After fitting, the update adds the learner’s predictions to the current predictions. A step factor may be included; this tutorial uses \(\alpha\) to make that scaling explicit, without requiring a particular method for choosing it.
The initial constant predictor is commonly chosen to minimize the empirical squared-error risk among all constants. Differentiating \(\sum_i\frac12(y_i-c)^2\) with respect to \(c\) gives \(-\sum_i(y_i-c)\). Setting this derivative to zero yields \(c=\bar y\), where \(\bar y=n^{-1}\sum_i y_i\). Thus \(F_0(x)=\bar y\) is a least-squares constant initialization.
Choose a starting predictor, often the constant \(F_0(x)=\bar y\).
At step \(m\), set \(r_{im}=y_i-F_{m-1}(x_i)\) for each training observation.
Find \(h_m\) that approximates the pseudo-residuals by minimizing their squared discrepancies over the training inputs.
Set \(F_m(x)=F_{m-1}(x)+\alpha h_m(x)\), using the specified step factor \(\alpha\).
Worked Updates
Worked Example: A Constant Learner
Take responses \(y=(2,4,6)\), initialize with \(F_0(x)=0\), and let the learner class contain only constants. The initial residuals are \(r=(2,4,6)\). The least-squares constant fitted to these residuals is their mean: \[ h_1(x)=\frac{2+4+6}{3}=4. \] With a full step, \(\alpha=1\), the updated prediction is \(F_1(x)=0+4=4\) for every input. The new residuals are \((-2,0,2)\), whose mean is zero, so another constant least-squares fit is zero and the predictor does not change.
The empirical risk before the update is \[ R(F_0)=\frac{1}{2(3)}(2^2+4^2+6^2)=\frac{56}{6}=\frac{28}{3}. \] After the update, it is \[ R(F_1)=\frac{1}{6}\{(-2)^2+0^2+2^2\}=\frac{8}{6}=\frac{4}{3}. \] The constant learner can correct the overall level of the predictions, but after that correction its residuals have mean zero. It cannot represent any further variation across inputs.
Worked Example: A Tree Learner With Two Leaves
Let \(n=4\), with responses \(y=(1,3,5,9)\), and start from the constant least-squares predictor \(F_0(x)=\bar y=18/4=4.5\). The pseudo-residuals are \[ r=(-3.5,-1.5,0.5,4.5). \] Suppose a regression tree splits the observations into a left leaf containing observations 1 and 2 and a right leaf containing observations 3 and 4. The least-squares prediction in each leaf is the mean residual in that leaf: \[ h_1(x)=\frac{-3.5-1.5}{2}=-2.5\quad\text{in the left leaf},\qquad h_1(x)=\frac{0.5+4.5}{2}=2.5\quad\text{in the right leaf}. \]
For a full step, the updated fitted values are \(4.5-2.5=2\) in the left leaf and \(4.5+2.5=7\) in the right leaf. The new residuals are \(1-2=-1\), \(3-2=1\), \(5-7=-2\), and \(9-7=2\). Their squared sum is \(1+1+4+4=10\), giving \(R(F_1)=10/8=1.25\). Initially the squared residuals summed to \(12.25+2.25+0.25+20.25=35\), so \(R(F_0)=35/8=4.375\). The tree has adapted the predictions to the two groups, reducing the empirical risk by \(4.375-1.25=3.125\).
Worked Example: A Tree Fitted to Nonzero Current Predictions
Suppose four responses are \(y=(4,6,7,11)\) and the current predictor has fitted values \((3,3,8,8)\) on the training inputs. The pseudo-residuals are therefore \((1,3,-1,3)\). A fixed two-leaf tree that groups observations 1 and 2 together and observations 3 and 4 together is fitted to these residuals. Its leaf predictions are \[ \frac{1+3}{2}=2\quad\text{and}\quad\frac{-1+3}{2}=1. \]
With \(\alpha=1\), the new fitted values are \((3+2,3+2,8+1,8+1)=(5,5,9,9)\). The updated residuals are \((-1,1,-2,2)\), with squared sum \(1+1+4+4=10\). The risk is \(10/8=1.25\). Before the update, the squared residuals summed to \(1+9+1+9=20\), so the risk was \(20/8=2.5\). This example makes the target distinction explicit: the tree was fitted to \((1,3,-1,3)\), the residuals from the current predictor, rather than to \((4,6,7,11)\), the original responses.
Why a Least-Squares Fit Reduces Risk
The decrease in the tree example follows from a general projection calculation. Fix a partition of the training observations into leaves and fit a constant residual prediction within each leaf. This is least-squares projection onto the vector space of vectors that are constant within each leaf. More generally, the same calculation applies whenever the fitted prediction vector is the least-squares projection of the residual vector onto a linear subspace. The partition or subspace must be fixed for the projection calculation; it may have been selected using the data, but the claimed identity concerns the resulting fitted vector and its least-squares fit.
Proof. Write \(h_i=h(x_i)\). Since \(h\) is the least-squares projection of \(r\) onto \(S\), the projection residual \(r-h\) is orthogonal to every vector in \(S\). In particular, \(h\in S\), so \(\sum_i(r_i-h_i)h_i=0\). Rearranging gives \(\sum_i r_i h_i=\sum_i h_i^2\).
The updated residual for observation \(i\) is \(y_i-\{F(x_i)+\alpha h_i\}=r_i-\alpha h_i\). Expand the difference in empirical risks: \[ R(F_{\mathrm{new}})-R(F)=\frac{1}{2n}\sum_i\{(r_i-\alpha h_i)^2-r_i^2\} =\frac{1}{2n}\left(-2\alpha\sum_i r_i h_i+\alpha^2\sum_i h_i^2\right). \] Substitute \(\sum_i r_i h_i=\sum_i h_i^2\) to obtain the stated identity. The coefficient \(-\alpha+\alpha^2/2\) is negative exactly when \(0<\alpha<2\); when \(h\) is nonzero, its squared norm is positive, so the risk strictly decreases. At \(\alpha=1\), the coefficient is \(-1/2\), giving the asserted decrease. \(\square\)
For a fixed tree partition, the vectors that are constant within each leaf form a linear subspace. The least-squares fit in each leaf is its mean residual, so the theorem applies to that fit. If the learner class is more restricted or its fit is only approximate, the projection identity need not hold; one should not claim this exact risk decrease without verifying the relevant least-squares property.
Common Mistakes and Practical Meaning
- Using the original responses as the new target. That would fit \(h\) to \(y_i\), ignoring the current predictor. The correct targets are \(r_i=y_i-F(x_i)\); the new learner is added to \(F\).
- Putting \(1/n\) into the individual-loss derivative. The derivative of \(\frac12(y_i-z)^2\) is \(-(y_i-z)\). The factor \(1/n\) appears in the derivative of the averaged empirical risk with respect to the fitted-value coordinate.
- Assuming every learner class makes the same update. A constant learner can adjust only the overall level. A tree can assign different residual averages to different regions of the input space.
- Claiming that any fitted learner must decrease training risk. The exact projection result requires a least-squares projection onto a linear subspace, and its strict decrease requires a nonzero fit and \(0<\alpha<2\).
Least-squares pseudo-residuals make the gradient step tangible: they identify which observations are underpredicted or overpredicted and by how much. Fitting a tree to them creates a structured correction, while the additive update preserves the contributions of earlier learners. This is the basic mechanism behind regression boosting with squared-error loss.
Check Your Understanding
Use the definitions and calculations above to answer these questions.
- For \(L(y,z)=\frac12(y-z)^2\), derive the pseudo-residual when the current fitted value is \(F(x_i)\).
- Explain why the individual-loss derivative and the empirical-risk coordinate derivative differ by a factor of \(1/n\).
- If a tree has leaves containing residuals \((2,4)\) and \((-1,5,8)\), what is its least-squares prediction in each leaf?
- State the projection condition needed for the exact risk-change identity, and the range of \(\alpha\) that gives strict decrease when the fitted learner is nonzero.
- Why might fitting a constant learner to residuals stop changing the predictor after one full step from a constant initialization?