Search

Search papers and lessons

Ordered Boosting

Level 4 · 11 min read

Ordered boosting computes each training example's residual with a model that never saw that example, which removes the prediction shift that makes ordinary gradient boosting overfit its own targets.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Discrete math
  • Classical models
  • Learning basics
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

Gradient boosting builds a model in rounds, and each round fits a new tree to the errors the current model still makes on the training data. Ordered boosting changes one thing: when it computes the error for a training example, it uses a model that was trained without that example. The model therefore never grades an example with a score that already contains that example's own label, which removes a bias the paper calls prediction shift.

Builds on: Gradient Boosting, Target Statistics · Leads to: CatBoost

Where it's used

Click prediction with user and topic combinations. An advertising model predicts whether a user clicks an ad. Two categorical columns, the user ID and the ad topic, carry much of the signal together. The CatBoost paper builds combinations of such columns during training and converts them into numbers with Target Statistics. Ordered boosting is what keeps those numbers from leaking each row's own label into the model that scores that row.

Tabular prediction benchmarks. The CatBoost paper compares its ordered mode with XGBoost and LightGBM on several public tabular datasets and reports that CatBoost scores best on all of them, with its significance tested by a paired one-tailed t-test. The comparison is the paper's own claim and should be read with the setup in its appendix in mind.

Choosing a boosting mode in practice. CatBoost offers two modes, Ordered and Plain. On the Epsilon dataset the paper reports that Ordered mode runs about 1.7 times slower than Plain, so it is a deliberate trade of time for less bias.

How it works

The idea is easiest to see with no features at all. We predict a single number, and the model at every step is the average of the targets it has seen so far. Four examples arrive in a random order, with targets 1, 3, 5 and 7.

  1. Fix an order. Draw a random permutation of the training examples. Say the order is the same as the list: examples A, B, C, D with targets 1, 3, 5, 7.
  2. Keep a model for each prefix. Build a supporting model M1M_1 from the first example, M2M_2 from the first two, and so on. Here M0M_0 predicts 0, because nothing has been seen yet.
  3. Compute each residual with the earlier model. For example A, use M0=0M_0 = 0: the residual is 1−0=11 - 0 = 1. For B, use M1M_1, the mean of {1}\{1\}, which is 1: the residual is 3−1=23 - 1 = 2. Check: B's own target 3 never entered the number it was compared with.
  4. Continue along the order. For C, use M2M_2, the mean of 1 and 3, which is 2: the residual is 5−2=35 - 2 = 3. For D, use M3M_3, the mean of 1, 3 and 5, which is 3: the residual is 7−3=47 - 3 = 4. Check: every residual was computed by a model that had not seen its own example.
  5. Fit the tree to these residuals. The next tree is fitted to residuals 1, 2, 3, 4 instead of to residuals taken from a model that already saw every target.
  6. Use one model at test time. A new example is scored by the final model, which is built from all the examples. No supporting model is used for prediction.
flowchart LR
  P["Random order A, B, C, D"] --> M0["M0 predicts 0"]
  M0 --> R1["Residual for A uses M0"]
  P --> M1["M1 fitted on A"]
  M1 --> R2["Residual for B uses M1"]
  P --> M2["M2 fitted on A and B"]
  M2 --> R3["Residual for C uses M2"]
  R1 --> T["Fit the next tree to residuals"]
  R2 --> T
  R3 --> T

Step 3 is the whole idea. Ordinary gradient boosting would use one model trained on all four examples, which contains each target, and would compute residuals from it. For this toy, that model is the mean 4, so the residuals are −3,−1,1,3-3, -1, 1, 3. Those residuals already reflect the targets they are supposed to predict, and that is the leak.

The math

Gradient boosting with squared loss starts from a model F0F^{0} and repeats: compute residuals rk=yk−Ft−1(xk)r_k = y_k - F^{t-1}(\mathbf{x}_k), fit a tree hth^{t} to them, and set Ft=Ft−1+αhtF^{t} = F^{t-1} + \alpha h^{t} with a step size α\alpha. The residual is the negative gradient of the squared loss, up to a constant factor.

Step 3 in symbols: the residual with a supporting model

Let σ\sigma be the random permutation. Write MjM_j for the model trained on the first jj examples in the order. Ordered boosting computes the residual for the example in position jj as

rσ(j)=yσ(j)−Mj−1(xσ(j))r_{\sigma(j)} = y_{\sigma(j)} - M_{j-1}(\mathbf{x}_{\sigma(j)})

The subscript j−1j-1 means that the model has seen only examples that come before position jj. The residual never uses the target of the example it is computed for.

Check on the toy: with targets 1, 3, 5, 7 in this order, the residuals are 1−01 - 0, 3−13 - 1, 5−25 - 2, 7−37 - 3, which is 1,2,3,41, 2, 3, 4. These match step 3 of the walkthrough.

Why the bias appears in ordinary boosting

The CatBoost paper studies a regression case with two independent binary features x1,x2x^1, x^2, each equal to 0 or 1 with probability one half, and a target y=c1x1+c2x2y = c_1 x^1 + c_2 x^2. It runs two boosting steps with decision stumps, one on each feature, and trains both steps on the same data set of size nn. Its Theorem 1 states that the expected prediction on a new point is

E F(x)=f∗(x)−1n−1 c2(x2−12)+O(2−n)\mathbb{E}\, F(\mathbf{x}) = f^{*}(\mathbf{x}) - \frac{1}{n-1}\, c_2 \left(x^2 - \tfrac{1}{2}\right) + O(2^{-n})

where f∗(x)=c1x1+c2x2f^{*}(\mathbf{x}) = c_1 x^1 + c_2 x^2 is the true function. The extra term is a bias that shrinks in proportion to 1/(n−1)1/(n-1). If the two steps use independent samples, the bias term disappears (up to an exponentially small term), so the leak comes from reusing one sample.

Ordered boosting in symbols

Ordered boosting is designed so that each residual rσ(j)r_{\sigma(j)} is computed from Mj−1M_{j-1}, which uses only earlier examples. Keeping a separate prediction for every prefix is too costly, so CatBoost stores predictions only at power-of-two prefix lengths and uses several permutations.

Worked examples

Example
Tiny: residuals in a fixed order

Four examples arrive in the order with targets 1, 3, 5, 7. Compare ordered and ordinary residuals.

  1. Ordinary. Train one model on all four targets. Its prediction is the mean, (1+3+5+7)/4=4(1 + 3 + 5 + 7)/4 = 4. Residuals are 1−4=−31 - 4 = -3, 3−4=−13 - 4 = -1, 5−4=15 - 4 = 1, 7−4=37 - 4 = 3. Interpretation: the residuals are centred on zero because each target shaped the model that predicts it.
  2. Ordered, first example. Use M0=0M_0 = 0. Residual 1−0=11 - 0 = 1.
  3. Ordered, second example. Use M1=1M_1 = 1. Residual 3−1=23 - 1 = 2.
  4. Ordered, third example. Use M2=(1+3)/2=2M_2 = (1 + 3)/2 = 2. Residual 5−2=35 - 2 = 3.
  5. Ordered, fourth example. Use M3=(1+3+5)/3=3M_3 = (1 + 3 + 5)/3 = 3. Residual 7−3=47 - 3 = 4.
  6. Interpretation. The ordered residuals are all positive here because each example is larger than the average of the examples before it. That is a property of this increasing order, not a bug. What matters is that no residual uses its own target.
Example
Standard: the bias in the two-feature toy

Use the bias term 1n−1c2(x2−12)\frac{1}{n-1} c_2 (x^2 - \frac{1}{2}) from the Theorem, with c2=2c_2 = 2 and a test point where x2=1x^2 = 1.

  1. Factor x2−12x^2 - \frac{1}{2}. It is 1−0.5=0.51 - 0.5 = 0.5.
  2. Multiply by c2c_2. 2×0.5=12 \times 0.5 = 1.
  3. Sample size n=5n = 5. The factor 1n−1\frac{1}{n-1} is 14\frac{1}{4}. The bias is −14×1=−0.25-\frac{1}{4} \times 1 = -0.25.
  4. Sample size n=21n = 21. The factor is 120\frac{1}{20}. The bias is −120×1=−0.05-\frac{1}{20} \times 1 = -0.05.
  5. Interpretation. Reusing one sample for both steps gives a bias that is smaller with more data but never disappears. Ordered boosting removes the term at its source, rather than waiting for nn to grow.
Example
Realistic: how many values to store

A practitioner trains on 200,000 rows with s=4s = 4 random permutations. A naive implementation of ordered boosting keeps a supporting prediction for each example at each prefix length, which is s⋅n2s \cdot n^2 values in total.

  1. Square the rows. 2000002=4×1010200000^2 = 4 \times 10^{10}.
  2. Multiply by ss. 4×4×1010=1.6×10114 \times 4 \times 10^{10} = 1.6 \times 10^{11} values. That is too much memory for a typical machine.
  3. The CatBoost trick. Keep supporting predictions only at prefix lengths that are powers of two, 2,4,8,…2, 4, 8, \ldots up to nn. For n=200000n = 200000 that is ⌈log⁡2200000⌉=18\lceil \log_2 200000 \rceil = 18 prefix lengths, so the count is about s⋅n⋅18=4⋅200000⋅18=1.44×107s \cdot n \cdot 18 = 4 \cdot 200000 \cdot 18 = 1.44 \times 10^{7} values.
  4. Interpretation. The trick is why ordered mode is practical. The values drop from about 101110^{11} to about 10710^{7}, which is a large saving, though still more than ordinary boosting stores for one model on the same rows.
  5. Try it: with n=1000000n = 1000000 and s=2s = 2, what is the naive count s⋅n2s \cdot n^2? Answer: 2×10122 \times 10^{12} values, which is why the power-of-two reduction is needed.

Common mistakes and tradeoffs

It is tempting to think that ordered boosting is just bagging with extra steps. In fact bagging averages models trained on resamples to reduce variance, as in Bagging. Ordered boosting targets a bias that comes from target leakage inside the boosting loop, and it does not average anything at prediction time.

It is tempting to think that ordered boosting always wins. In fact it costs time and memory, and the paper reports about 1.7 times the running time of Plain mode on Epsilon. Plain mode is a sound choice when the data has no categorical features and training speed matters more than the last bit of accuracy.

It is tempting to think that the first few examples in a permutation are as useful as the later ones. In fact the earliest examples have short histories, so their supporting predictions have high variance. CatBoost discards those early residuals when it scores candidate splits, as the implementation details describe.

Use ordered boosting when the data has many categorical features or small data where leakage is likely, and when the extra cost is acceptable. Do not use it as a cure for Overfitting in general: it addresses one specific bias, and it does not replace early stopping or regularisation.

History

Gradient boosting was framed as gradient descent in function space by Friedman in the late 1990s and published in 2001, which made it a general recipe for boosting any differentiable loss with trees. Breiman had earlier proposed iterated bagging for a related residual problem. The CatBoost paper, posted in 2017, pointed out that the residuals used in boosting carry a shift that earlier work had noticed without formalising, and it proved the bias for a simple case. Ordered boosting is the response to that analysis.

Recap

  • Ordinary gradient boosting computes residuals with a model trained on the same examples, which leaks each target into its own residual.
  • Ordered boosting computes the residual for position jj with a model Mj−1M_{j-1} that saw only earlier examples.
  • The exact method needs many models, so CatBoost uses a cheaper version with several permutations, oblivious trees and a power-of-two storage trick.
  • Next, read the CatBoost paper, which puts this idea together with Target Statistics for categorical features.

Check yourself

QuestionExamples arrive in the order with targets 2, 4, 6. What are the ordered residuals, using the rule that the first model predicts 0 and each later model predicts the mean of the earlier targets?Show answer

The first residual is 2−0=22 - 0 = 2. The second uses the mean of {2}\{2\}, which is 2, so the residual is 4−2=24 - 2 = 2. The third uses the mean of {2,4}\{2, 4\}, which is 3, so the residual is 6−3=36 - 3 = 3. The answer is 2,2,32, 2, 3. No residual uses its own target.

QuestionOrdinary gradient boosting trains on all the data and then computes residuals on the same data. Explain in one or two sentences why this makes the residuals look better than they are on new data.Show answer

The model that computes the residual has already seen the example's target, so the residual is partly a measure of memorisation rather than of error on unseen data. The training residuals are therefore shrunk toward zero compared with the residuals a new example would produce, and the next tree learns from a biased signal.

QuestionIn the CatBoost paper's two-feature toy, the bias is −1n−1c2(x2−12)-\frac{1}{n-1} c_2 (x^2 - \frac{1}{2}). Why does the bias vanish when the two boosting steps use independent samples?Show answer

With independent samples, the second step's residuals come from a model that was trained on different examples from the ones it is fitted to. The shift that comes from using the same examples twice is absent, and the Theorem reports an expectation with no 1n−1\frac{1}{n-1} term, up to an exponentially small remainder.

QuestionA team with a large categorical data set sees their model do well in cross-validation but poorly on a later time window. They suspect target leakage in boosting. Which change addresses their suspicion most directly, and what does it cost?Show answer

Switching to ordered boosting addresses leakage in the residuals most directly, because each residual is computed by a model that never saw that example. The cost is extra training time and memory, since the supporting models must be maintained. The paper reports that on the Epsilon dataset Ordered mode is about 1.7 times slower than Plain mode. The team should also check that the ordering used for their categorical encoding is consistent with the boosting permutations, so that the encoding does not reintroduce the same leak.

Sources

Ordered Boosting — explained simply · ungoon.me