CatBoost (Categorical Boosting)

CatBoost is a state-of-the-art open-source machine learning algorithm based on gradient boosting over decision trees, designed specifically for categorical features, with clever techniques to prevent overfitting and target leakage.
CatBoost delivers high accuracy with little to no hyperparameter tuning, and offering blazing-fast prediction speeds

While Boosting - XGBoost optimized for speed and LightGBM for scale. CatBoost is built to solve a different problem: how to handle categorical features properly without data leakage.

The Categorical Feature Challenge

Real-world datasets are full of categorical features — user IDs, product categories, locations, brands, etc. Before a gradient-boosted tree can split on them, they must be turned into numbers, and every traditional way of doing so has a serious flaw:

One-Hot Encoding:

Label Encoding:

Target Encoding (see Target Encoding):

So what does CatBoost do differently?

Target Encoding is the most predictive option but the most leak-prone. Rather than abandon it, CatBoost fixes the leakage with Ordered Target Encoding Statistics — encoding each row using only the rows seen before it (covered next).

Key Features

1. Native Categorical Support

Eliminates the need for extensive data preprocessing like one-hot encoding. It converts categories into numerical values using innovative, permutation-driven target statistics, preventing data leakage.

CatBoost introduces the concept of "artificial time."

By relying only on the "past," CatBoost completely eliminates target leakage while generating highly accurate encodings on the fly.

2. Ordered Boosting

One of the most innovative features of CatBoost is Ordered Boosting, which addresses the issue of prediction bias during training.

How Standard Gradient Boosting Works:

For Category "A":
- Calculate: Average of ALL samples with Category "A"
- Use this average for EVERY sample with "A"
Problem: Future data used to encode past data!

Ordered Boosting Process:

For each sample i with Category "A":
- Calculate: Average of samples 1 to i-1 with Category "A"
- Use this for sample i
- Next sample sees average including sample i
Result: Only past information used—no leakage!

Example: Encoding "City" feature

Order City Target Traditional (Leaky) CatBoost (Ordered)
1 NYC 1 0.75 (uses all) 0.5 (no prior data, use global avg)
2 NYC 0 0.75 (uses all) 1.0 (only sample 1: 1/1)
3 LA 1 0.67 (uses all) 0.5 (no prior LA data)
4 NYC 1 0.75 (uses all) 0.5 (samples 1,2: 1/2)

Benefits:

3. Oblivious (Symmetric) Trees

Uses symmetric decision trees, meaning the same splitting criterion is used across all nodes at a specific depth.

Standard Trees:

CatBoost's Oblivious Trees:

Visualization:

Standard Tree:           Oblivious Tree:
     Age                      Age
    /   \                    /   \
  Sex   Income          Income Income
  / \    / \              / \     / \
 A  B   C  D             A  B    C  D

Benefits:

Trade-off: Slightly less flexible than asymmetric trees, but the regularization benefit usually outweighs this.

4. Built-In Missing Value Handling:

Automatically processes missing values during both training and inference without requiring prior imputation.

5. The Shuffle

If you look at an entire dataset all at once, it is easy for a model to accidentally peek at the answers. To stop this, CatBoost takes your training data and randomly shuffles the rows into a sequence. The algorithm then pretends that this data is arriving sequentially over time, one row after another.

CatBoost goes even further: it uses different random permutations of data for:

This creates additional protection against overfitting—the same data points don't repeatedly influence both residual calculation and tree building.

Key Components in CatBoost

  1. Loss Functions:
    • Supports a variety of objective functions like log loss, MAE, RMSE, and cross-entropy, making it versatile across tasks (classification, regression, ranking).
  2. Feature Combinations:
    • CatBoost creates combined feature interactions during training automatically.
  3. Hyperparameter Optimization:
    • Includes parameters such as learning rate, number of iterations, tree depth, and regularization factors.
  4. GPU and Distributed Training:
    • CatBoost’s support for GPU and distributed systems ensures scalability for massive datasets.

Training Process

How to Use CatBoost with Categorical Features

Super Simple:

# No preprocessing needed!
import catboost as cb

# Just specify which columns are categorical
cat_features = ['City', 'Category', 'Brand', 'UserID']

model = cb.CatBoostClassifier(
    cat_features=cat_features,  # That's it!
    iterations=1000,
    learning_rate=0.1
)

model.fit(X_train, y_train)

CatBoost Characteristics

Strengths:

Weaknesses:

When to Choose CatBoost: