Categories like user IDs or zip codes are hard: replace each one by its average label and the model can end up peeking at the answer. CatBoost encodes every row using only the rows that came before it, then grows perfectly symmetric trees. Watch the leak, then watch it get reduced.
A category becomes a smoothed target statistic: TS = (Σy + a·p) / (n + a), where Σy is the sum of labels counted, n is how many rows were counted, p is the overall average label (the prior) and a is the prior weight that pulls rare categories toward p. The naive version counts every row of the category, including the row being encoded, so a rare category’s number contains its own label. The ordered version shuffles the rows and encodes each one using only the rows before it (n = preceding rows of that category). CatBoost supports several categorical-processing schemes; this page shows just this one.
If the dots in the top strip split cleanly by colour, the encoded value is carrying the row’s own label: a tree can split on it, look brilliant on training data, and then do worse on new rows whose encoding never contained their own label. In the ordered strip the colours stay mixed, because a row’s encoding never saw its own answer. This is a risk, not a guarantee: naive encoding does not make every model worse on every dataset, and it hurts most for rare categories.
Simplification: this page uses a single random order, which is the easiest way to see the idea. The real CatBoost algorithm uses several permutations and applies the procedure during training, so treat the row-by-row table as an illustration rather than the exact implementation.
A normal tree can ask a different question at every node. CatBoost’s oblivious trees ask the same question at every node of a level, so a tree of depth d is just d questions and up to 2d leaves (two to the power d; some leaves may end up with no training rows). This is a strong regulariser, and it makes prediction very fast. The map shows what one tree contributes across the categories and the numeric feature.
Both boosted models below use the same trees settings, learning rate and data. Only the encoding differs. Accuracy is always measured with the encoding a new row would receive. Naive target encoding can leak a training row’s own label into its feature value. That can make training performance look artificially good and encourage overfitting, especially for rare categories. Ordered statistics reduce this risk by using only preceding observations in a permutation. The log-loss gap is the useful signal: two models can have the same rounded accuracy while one is more overconfident on its training rows.
Categories carry no real signal here. Use the naive encoding, go deep, boost 40 rounds, and watch it memorise.
Same data, same trees, ordered encoding. The leak is reduced and the validation gap usually shrinks.
Make the categories truly informative. Now the encoding earns its keep and both modes can do well.