A tree with a single split predicts only two values, while a deep tree can follow its training data so closely that it predicts new cases poorly. Boosting methods take a middle path. They start from a simple prediction, fit a small tree to what the current model still gets wrong, accept part of that correction and repeat. What exactly should each new tree fit when the loss is not squared error, and how many corrections should be accepted? This lesson derives the training signal from the loss, shows that ordinary residuals are the special case of squared error, contrasts the reweighting used by AdaBoost, and explains why the learning rate, the number of stages and the tree depth are chosen on validation data.
Key terms
Stagewise additive model
Definition A stagewise additive model predicts with a sum of simple functions that are added one stage at a time. After stages it has the form
where is a starting model, usually a constant, each is a function returned by a base learner and each is a real coefficient. Forward stagewise fitting builds the sum greedily for a chosen loss and training examples . At stage the earlier terms are frozen, and only the new term is chosen, to make the training loss
small, after which . Earlier terms are never refitted, which separates this from fitting all the terms jointly. Boosting methods are the learning algorithms that build such a sum in sequence, with each new term responding to the errors of the current model. Bagging, by contrast, fits its trees independently on bootstrap samples and averages them. In the gradient boosting of this page every coefficient equals a fixed learning rate, , and the size of each correction sits in the leaf values of the tree .
In plain words The model is a starting guess plus a list of corrections. Each stage looks at the current model, adds one more correction and never goes back to edit the earlier ones. The prediction at an input is the starting value plus every correction that applies there. Simple corrections add up to a flexible function, which is why a sum of many small trees can describe patterns that no single small tree can.
Example Start from the constant on one feature , accept half of each correction, and add two stumps. The first outputs for and otherwise, and the second outputs for and otherwise. The model then takes three values,
For instance, at it adds from the first stump and from the second. Each stump predicts two values, and their sum is a staircase with three steps.
Weak learner
Definition A weak learner, or base learner, is a fitting procedure that returns a function from a restricted class . Typical classes are decision stumps, which are trees with one split and two leaves, and regression trees limited to a small depth or a small number of leaves. In the classical analysis of boosting algorithms for binary labels, a learner is weak in a precise sense if there is a fixed such that, for every weighting of the training examples, it returns a classifier with weighted error at most , so it is reliably a little better than guessing. In gradient boosting the word is used more loosely for a low-capacity learner, usually a shallow regression tree fitted by least squares. Each leaf of a tree of depth is described by at most split conditions, so the tree is a sum of terms that each depend on at most features, and so is any sum of such trees. A sum of stumps is therefore additive in the features, of the form , with no interactions.
In plain words A weak learner is deliberately too simple to fit the data on its own. Its value lies in being quick to fit and stable, so that many of them can be added in small steps. The depth of the trees decides what kind of pattern the whole sum can express. Stumps can only add up separate effects of single features, while trees of depth can also describe how two features act together.
Example Take the four points , , and with labels , , and , the exclusive-or pattern. Every stump splits on one feature, and each of its two sides then contains one point of each label, so under equal weights every stump has weighted error exactly . Stumps are not weak learners for this problem in the classical sense, and no sum of stumps classifies all four points correctly by its sign, however many stages it has. Such a sum has the form , and correct signs would need
The first two inequalities add up to a negative number and the last two to a positive one, yet both totals equal . A single tree of depth that splits on and then on classifies all four points correctly.
Negative gradient
Definition Let the loss be differentiable in the prediction or score for each target value . At stage the negative gradient, or pseudo-residual, of training example is the negative derivative of its loss with respect to the prediction, evaluated at the current prediction,
The vector is the negative gradient of the training loss with respect to the vector of training predictions, at the current predictions. Moving those predictions a short enough step along it lowers the training loss whenever it is not the zero vector. For the squared loss the derivative is , so the pseudo-residual is the ordinary residual . For binary labels and a log-odds score with probability , the log loss
equals when and when . Its derivative is , so the pseudo-residual is , the label minus the current probability. For the absolute loss it is wherever , and the loss has no derivative where .
In plain words The pseudo-residual says, for each training example, which way its prediction should move to lower that example’s loss and how fast the loss changes in that direction. It exists only at the training inputs, since a new input has no target. That is why gradient boosting fits a function to these numbers, so that the correction can be applied anywhere. The loss decides what counts as an error. Squared error turns the signal into the ordinary residual, and the log loss turns it into the label minus a probability, a number between and .
Example For squared error, four training targets , , and and the constant prediction give the pseudo-residuals , , and . For the log loss, a positive example with current score has probability and pseudo-residual , a small push upward because it is already classified with confidence. A negative example with the same score has pseudo-residual , a strong push downward. Subtracting the score from the label instead would give for the positive example, a push in the wrong direction, because labels and probabilities lie in while a score can be any real number.
Gradient boosting
Definition Gradient boosting with a differentiable loss , a class of regression trees, a learning rate and a number of stages fits training examples , , in three steps.
- Set to the constant that minimizes . For squared error this is the mean of the targets, and for the log loss it is , where the share of positive labels must lie strictly between and .
- For , compute the pseudo-residuals at the current predictions, fit a tree from to the pairs by greedy least-squares splitting, and set .
- Return , and for the log loss also the probability estimate .
The tree is an approximation of the negative gradient that can be evaluated at any input. Many implementations then replace each leaf value by the constant that lowers the original loss most on the examples in that leaf, or use second derivatives of the loss, and stochastic gradient boosting fits each tree to a random subsample of the rows. Residual fitting is the squared-error case. With the pseudo-residuals are the ordinary residuals, a least-squares tree predicts the mean residual in each leaf, and the leaf adjustment just described changes nothing. Fitting ordinary residuals under a loss whose negative gradient is not a multiple of the residual, such as the log loss or the absolute loss, is a different algorithm, not gradient boosting for that loss.
In plain words Gradient descent would move every training prediction along the negative gradient, but a model must also predict at inputs it has never seen. Gradient boosting therefore fits a small tree to the desired moves and takes the step along the tree, so that nearby inputs receive similar corrections. For squared error this is the familiar idea of fitting the next tree to what the current model still gets wrong.
Example Take four constructed training examples with inputs , , and and targets , , and , squared error, stumps that split midway between neighboring inputs, and . The constant model predicts the mean , with residuals , , and and sum of squared errors . The best stump for these residuals splits at , with leaf means and and a residual sum of squares of around them, against for the splits at and . Adding half of it gives the predictions
at the four inputs, with residuals , , and and sum of squared errors . At the second stage the split at wins again, with against , and its leaf means are and . Half of that correction gives
and the sum of squared errors falls to . The second improvement, , is smaller than the first, , because the residuals left to correct are smaller. Applying the learning rate twice, once to the residuals before fitting and again to the update, would add only at the first stage, which is a different algorithm with an effective rate of .
Shrinkage and number of stages
Definition Shrinkage multiplies each fitted correction by a learning rate with before adding it, so that . The number of stages is the number of fitted trees in the sum. Together with the tree size, set by the depth, the number of leaves or the minimum leaf size, and any row subsampling, they are hyperparameters, chosen with validation data or with cross-validation inside the training data and never with the test set. For squared error with least-squares leaf values, the values of a tree at the training inputs are the orthogonal projection of the residual vector onto the span of the tree’s leaf indicator vectors, so the training sum of squared errors changes by
It never increases for , and it falls strictly whenever the new tree is not zero at every training input. The loss on validation data usually falls at first and can rise later, once the trees start to fit noise. Early stopping adds stages while monitoring the validation loss, often stops after a set number of stages without improvement, and keeps the stage count with the lowest validation loss.
In plain words The learning rate decides how much of each proposed correction to accept, and the number of stages decides how many corrections accumulate. A smaller rate usually needs more stages to reach the same training fit, and in practice it often predicts new data better, at the cost of more computation, but neither choice is guaranteed to help. Deeper trees make each stage more flexible and let it model interactions among more features. Since the training loss falls almost regardless of these settings, all three are chosen together by validation loss, as in hyperparameter search. The data used for early stopping have taken part in choosing the model, so a final claim needs data used for nothing else. With the log loss, the probabilities can be poorly calibrated, so they need checking, and possibly recalibration, on held-out data before they drive decisions.
Example In the two stages above, , and the corrections have and . The identity gives and , as computed directly. With the first stage alone would reach , the spread left inside the two leaves. Now score two separate constructed validation examples, inputs and with targets and . With the predictions are and after no stage, and after one and and after two, so the mean absolute error falls from to to . The full step would predict and after one stage, with error , so on these data the smaller rate is not better. Two constructed points cannot settle such a choice. If they are used to pick the rate or the stage count, they are validation data, and a final claim needs further cases.
AdaBoost
Definition AdaBoost, short for adaptive boosting, is a boosting algorithm for binary labels . It starts with weights and repeats three steps for .
- Fit a classifier with values in to the weighted training data, and compute its weighted error , the total weight of the examples with .
- Provided , give it the vote weight .
- Multiply each weight by , which is for a correct example and for a mistake, and divide by the total so that the weights again sum to .
The final classifier is the sign of , with a stated rule for a score of exactly . An error means a classifier that is perfect on the training data, and means no improvement over guessing, so the standard algorithm stops in both cases instead of putting them into the logarithm. After each update, the examples misclassified by hold total weight exactly . The training error of the final classifier, counting a score of as an error, is at most
and this bound goes to as stages are added when every for a fixed . When each classifier minimizes the weighted error over its class, AdaBoost is forward stagewise fitting of the exponential loss , and its weights are proportional to , the size of that loss’s negative gradient at each example.
In plain words AdaBoost keeps the labels fixed and changes how much each example counts. Examples that the current classifier gets wrong gain weight, so the next classifier is pushed toward them, and the vote weight gives more say to classifiers with lower weighted error. Gradient boosting keeps the examples equally weighted and changes the targets that the next tree fits instead. The vote weight is computed from the data at each stage, while the learning rate of gradient boosting is a setting fixed in advance. Weight grows exponentially on examples that keep being misclassified, so mislabeled examples can draw more and more attention. With noisy labels the number of stages needs validation like any other setting, and a loss that grows more slowly for badly misclassified examples, such as the log loss, is a common alternative.
Example Four training examples start with weight each, and the first stump misclassifies one of them, so and
The mistaken example is multiplied by and the others by , a ratio of . The total before dividing is , which equals , the first factor of the bound. The new weights are for the mistaken example and for each of the three others. Under these weights the first stump has error exactly , so fitting it again would earn the vote weight , and the next stump has to classify differently.
Check yourself
- A current model predicts for a training example with target , and the loss is . The next tree outputs at this input and the learning rate is . Find the pseudo-residual, the new prediction and the loss before and after the update, and explain why the tree’s output differs from this example’s residual.
Show the answer
The pseudo-residual is the ordinary residual . The accepted update is , so the new prediction is
The loss falls from to . The tree was fitted to the residuals of all the training examples at once, and each of its leaves predicts the mean residual of the examples in that leaf, so its output is an average over this example’s leaf rather than this example’s own . Shrinkage then accepts only a fifth of it. The lower loss on one training example checks the arithmetic, but it says nothing about the loss on new data.
- A gradient boosting classifier uses the log loss with labels in and log-odds scores. A positive training example has current score and a negative one has current score . A colleague fits the next tree to the label minus the score. Compute the colleague’s targets and the correct pseudo-residuals, and say which way each one pushes the score.
Show the answer
The current probabilities are and . The derivative of with respect to is , so the pseudo-residuals are
The first raises the score of the positive example a little and the second lowers the score of the negative example, and both moves lower the log loss, which is about and for the two examples now. The colleague’s targets are and . They push the positive example’s score down and the negative example’s score up, so both point the wrong way. The label minus the score treats a label in as a target for a log-odds score that can be any real number, which is the negative gradient of a squared error between the two, not of the log loss.
- An analyst fits gradient-boosted regression trees of depth with learning rates and , adds up to stages, and for each rate keeps the stage count with the lowest loss on the test set. The training loss falls at every stage for both rates. The analyst concludes that more stages never hurt, picks the better rate, and reports its best test loss as the expected loss on new data. What is wrong, and what would a sound procedure look like?
Show the answer
A falling training loss is expected and proves little. For squared error each stage changes the training sum of squared errors by , which is never positive, so the training curve cannot show when later trees start to fit noise. On data not used for fitting, the loss usually stops improving at some stage and can rise afterward, so the claim that more stages never hurt is not supported.
Choosing the stage count and the rate by test loss uses the test set for selection. The reported number is the smallest of test losses, one for each rate and stage count, and the smallest of many noisy estimates tends to lie below the loss of the chosen model on fresh data, so the report is optimistic.
A sound procedure splits the training data into a fitting part and a validation part, or uses cross-validation inside the training data, with folds that keep groups together or respect time order when the data require it. For each rate and depth, stages are added while the validation loss is monitored, and the rate, depth and stage count with the lowest validation loss are chosen. The chosen pipeline is then scored once on the test set, or the whole tuning procedure is wrapped in nested cross-validation. The settings interact. With rate each stage accepts percent of its tree’s correction instead of percent, so its best stage count is usually much larger, and each rate has to be compared at its own best stage count rather than at a shared one. Deeper trees capture interactions among more features and usually reach their best validation loss in fewer stages, with more variance in each tree.