Algorithm 47 of 50 · Phase 9 · Day 48 streak

CatBoost

Gradient boosting that treats categorical features as first-class citizens — and fixes the leakage everyone else quietly commits.
Ordered Target Statistics Ordered Boosting Oblivious Trees Supervised
CatBoost infographic: ordered target statistics, ordered boosting, oblivious trees, feature combinations
Visual style: watercolor-cards · generated with gpt-image-2

Core Concept

CatBoost is gradient boosting on decision trees, engineered around one observation: the standard ways of handling categorical features leak the target into the features. Naive mean-target encoding computes a category's average label using rows that include the row you are about to predict — so the model memorises rather than learns. CatBoost's answer is ordering. It draws random permutations of the data and, for every row, computes both its categorical encodings and its boosting residuals using only the rows that came before it. That single discipline removes target leakage and the subtler prediction shift that biases classic boosting. Add symmetric (oblivious) trees for regularisation and blazing inference, and you get a model that is unusually strong out of the box on tabular data full of high-cardinality categories.

encoding(xi) = ( Σj<i [xj=xi]·yj  +  a·P ) / ( Σj<i [xj=xi]  +  a )

Key Components

Encoding

Ordered Target Statistics

Each categorical value becomes a number derived only from prior rows in a random permutation, smoothed toward a prior P with weight a. No peeking at your own label — no leakage, and rare categories fall back gracefully to the prior.

Training

Ordered Boosting

The residual for example i is scored by a model trained without example i. Classic boosting reuses the same data to both fit and evaluate gradients, so residuals are optimistically biased — that is prediction shift. Ordering removes it.

Structure

Oblivious / Symmetric Trees

Every node at the same depth uses the same feature and threshold. The tree becomes a lookup over a bit-vector: heavy regularisation against overfitting, and inference that vectorises into a handful of CPU instructions.

Interactions

Feature Combinations

As trees grow, CatBoost greedily merges categoricals it has already split on into new combined categories (city×device). It discovers interaction terms you would otherwise hand-engineer.

How It Works

  1. Generate several random permutations of the training set. Different permutations are used for encodings and for gradient estimation, so no single ordering dominates.
  2. For every categorical value in a row, compute its ordered target statistic from preceding rows only, smoothed by prior P and weight a.
  3. Estimate the gradient/residual for each example using supporting models built on prefixes of the permutation — models that have not seen that example.
  4. Grow one oblivious tree: at each depth, pick the single (feature, threshold) pair that best reduces loss across all nodes at that level.
  5. Optionally forge new combination features from categoricals already used in this tree, then re-scan candidate splits.
  6. Add the tree scaled by the learning rate, and repeat for the chosen number of iterations with early stopping on a validation fold.

Boosting Family, Side by Side

DimensionCatBoostXGBoostLightGBM
CategoricalsNative, ordered TSManual encodeNative, greedy split
Tree shapeOblivious, symmetricDepth-wiseLeaf-wise (best-first)
Growth biasOrdered, low biasPrediction shiftPrediction shift
Tuning effortLow — strong defaultsModerateHigher (leaf count)
Inference speedVery fastFastFast
Sweet spotHigh-cardinality tabularDense numericVery large numeric

Real-World Applications

Search & recommendation rankingBuilt at Yandex for web search ranking, where query, region, and device IDs are enormous categorical spaces.
Credit scoring & fraud detectionMerchant ID, MCC code, and country are high-cardinality and leakage-prone — exactly CatBoost's design case.
Churn & propensity modellingPlan tier, acquisition channel, and support-ticket category combine into strong interaction signals.
Ad click-through predictionSymmetric trees give millisecond-scale scoring at ad-auction latency budgets.
Kaggle-style tabular baselinesOften the best first model on messy mixed-type data with almost no tuning.
Pitfall to internalise: do not one-hot or mean-encode your categoricals before handing them to CatBoost. Pass raw category columns via cat_features. Pre-encoding throws away the ordered statistic — you re-introduce the exact leakage CatBoost exists to prevent, and usually lose accuracy while doing more work.

Checkpoint — answer before you move on

  1. Why does naive mean-target encoding leak, and how does the ordered target statistic close the leak without discarding the target signal? Hint: think about which rows contribute to the encoding of row i.
  2. What is prediction shift in classic gradient boosting, and what does ordered boosting change about how residuals are computed? Hint: which examples was the model that scores example i trained on?
  3. Oblivious trees are strictly less expressive than free-form trees at the same depth. Name one accuracy-side benefit and one systems-side benefit that make the trade worth it. Hint: one answer is about variance, the other about how inference maps onto hardware.