Why is a gradient boosting leaf's value found by line search rather than averaging?
answer
- A stage does two separate optimisations
- The tree gives direction, not distance
- The leaf constant sees the real loss
- Gradients are only a linear approximation
- Absolute error gives a median, not a mean
basics
~20 sThe tree only chooses which rows move together; the leaf value is the constant that actually minimises the chosen loss for those rows given the current model. Under squared error that is their mean, under absolute error their median.
solid answer
~50 sA stage does two optimisations. First the tree is grown on the pseudo-residuals, usually by least-squares splitting, which fixes the partition -- the *direction* of the step. Then, for each terminal leaf, you solve a one-dimensional minimisation: pick the constant `c` minimising `sum over rows in the leaf of L(y_i, F_{m-1}(x_i) + c)`, using the true loss and the model's current predictions. That is the line search, and it fixes the *step length*. For squared error the two coincide -- the minimiser is the mean of the leaf's residuals -- which is why the line search is invisible in the simplest presentation. Under absolute error the pseudo-residuals are only signs, and the line-search solution is the median of the leaf's actual errors. Log loss has no closed form, so the leaf constant is solved approximately.
go deeper
You are unlikely to be asked this outright. Just hold on to the fact that each leaf outputs a single number and that under squared-error regression that number is the average error of the rows landing in the leaf.
Be able to separate the two steps of a stage -- growing the partition on gradients, then choosing a constant per leaf -- and to say why they coincide for squared error and diverge otherwise.
Show you know where robustness actually comes from: choosing absolute error but averaging the leaf's errors would throw most of it away. Be ready to explain that the leaf constant depends on the current model's predictions, so the same partition earns different values at different stages.
The angle to own is that the objective, not the tree, defines what the model optimises. When the business cost of an error is asymmetric or heavy-tailed, argue for encoding it in the loss so both the gradients and the leaf values follow, rather than bolting a correction on after training.
## Two optimisations per stage, not one A single stage of gradient boosting does two separate pieces of optimisation, and candidates who have only implemented the squared-error case usually notice only one of them. 1. **Find the partition.** A shallow tree is grown on the pseudo-residuals -- the negative gradients of the loss at the current predictions. This step decides *which rows get grouped together*. 2. **Choose the value for each region.** For each terminal leaf `j`, pick the single constant `gamma_j` that minimises the **actual loss** for the rows in that leaf, given everything the model already predicts for them: ``` gamma_j = argmin over c of sum over rows i in leaf j of L(y_i, F_{m-1}(x_i) + c) ``` That second step is the *line search*: a one-dimensional minimisation along the direction the tree just chose. The tree says -these rows should move together-; the line search says -and here is how far they should actually move.- ### Why averaging the gradients is not enough The tree in step 1 is normally grown by least-squares fitting on the pseudo-residuals, whatever the real loss is. That is a deliberate approximation: the gradient field is a linear approximation of the loss surface, and squared-error splitting on it is fast and well understood. But a linear approximation is only trustworthy for a small step, and the leaf value *is* the step. If you simply averaged the gradients inside the leaf and used that as the output, you would be trusting the linear approximation to tell you a magnitude, which it cannot do for a non-quadratic loss. For squared error the two steps agree exactly: the pseudo-residuals *are* the errors, and the constant minimising the sum of squared errors in a leaf is their mean. This coincidence is why the line search is invisible in the simplest presentation of the algorithm -- and why so many people believe -leaf value = mean of the residuals- is a law rather than a special case. ### The absolute-error case, where it becomes visible Take `L = |y - F|`. The pseudo-residuals are `+1` and `-1`, so their mean inside a leaf is a number between minus one and plus one that carries no information about how far off the predictions are. Averaging that would be nonsense as an update. Solve the line search instead: ``` gamma_j = argmin over c of sum over i in leaf j of |(y_i - F_{m-1}(x_i)) - c| ``` The constant minimising a sum of absolute deviations is the **median**, so the leaf value is the median of the leaf's current errors. Notice what has happened: the *direction* came from the signs, but the *magnitude* came from a robust order statistic of the real errors. That is why absolute-error boosting shrugs off an extreme target -- an outlier contributes one sign to the split search and one element to a median, never a magnitude that drags the update. Other losses give other closed forms or none at all. Log loss has no closed-form minimiser for the leaf constant, so implementations solve it approximately -- one cheap step of a numeric minimisation per leaf, computed from quantities the stage already has. ### The consequences worth stating in an interview - **The split search and the leaf values optimise different objectives.** Splits use a squared-error proxy on gradients; leaves use the true loss. Saying -the tree minimises the loss- is imprecise, and a good interviewer will probe it. - **Robustness lives in the leaf value as much as in the loss.** Choosing absolute error but then averaging the leaf's errors would discard most of the robustness you asked for. - **Leaf values depend on the current model, not just on the leaf's rows.** `F_{m-1}(x_i)` appears inside the minimisation, so the same partition would get different values at stage 3 and stage 300. - **The step is bounded by the loss, not by the tree.** For losses whose gradient saturates -- log loss, absolute error -- a leaf full of badly-missed rows cannot demand an unbounded jump, because the line search is solving the real loss, which stops rewarding movement past a point. ### How to say it in one breath The tree picks a direction in function space by fitting the negative gradient; the line search picks the step length inside each region by minimising the genuine loss. Mean under squared error, median under absolute error, an approximate solve under log loss -- one algorithm, three different leaf values, because the leaf value is defined by the objective and not by the tree.
- Why not just use the mean of the pseudo-residuals in every leaf?For squared error that is already the line-search answer, so nothing is lost. For any other loss the gradients are a linear approximation that carries direction but not reliable magnitude -- under absolute error they are only plus or minus one, so their mean says nothing about how far the leaf should move. The line search restores the magnitude from the true loss.
- Under absolute-error loss, why does one extreme outlier barely move a leaf's value?It contributes one sign to the tree's target and one element to a median, never a magnitude. Because the leaf constant is the median of the leaf's current errors, an arbitrarily large single error shifts the order statistic by at most one position instead of dragging an average.
- Does the line search apply to the split search as well?No. The partition is normally grown by least-squares fitting on the pseudo-residuals regardless of the real loss, because it is fast and the gradient field is a usable proxy for grouping rows. Only the terminal-node constants are re-optimised against the genuine loss, so the two halves of a stage optimise different objectives.
saying these in an interview costs you the question
- Says a leaf value is always the mean of its residuals
- Claims the split search minimises the true loss
- Confuses the leaf constant with the split threshold
- Thinks absolute-error boosting has no closed-form leaf value
- Ignores that the current model enters the leaf minimisation