Skip to content
SK Subham KumarTSF Hub · time-series forecasting
Machine learning2018TreesBoostingCategorical

CatBoost

Categorical Boosting

Gradient boosting that handles categorical features natively and resists overfitting with ordered boosting, a strong default for tabular forecasting.

Overview

Like XGBoost and LightGBM, CatBoost reframes forecasting as regression on engineered features: lags, rolling statistics and calendar variables. Its differences matter for time series: categorical columns (store ID, product family, month, holiday flag) are encoded with ordered target statistics, computed only from earlier rows, which avoids the target leakage that naive target encoding causes.

Ordered boosting applies the same idea to the gradient estimates, and oblivious (symmetric) trees use the same split at each depth, which makes models fast to evaluate and naturally regularised.

How it works

Boosting builds an additive model of \(M\) trees, each fitted to the negative gradient of the loss:

\[F_M(x)=\sum_{m=1}^{M}\eta\, f_m(x),\qquad f_m\approx\arg\min_f\sum_i\big(-g_i^{(m)}-f(x_i)\big)^2\]

A categorical value \(c\) in row \(k\) is replaced by a smoothed mean of the target over earlier rows with the same value, with prior \(P\) and weight \(a\):

\[\hat x_k=\frac{\sum_{jWhen to use it

Use it for

  • Retail and demand forecasting with many categorical drivers
  • Global models across many series (series ID as a category)
  • When you want strong results with little tuning

Avoid it for

  • Pure trend extrapolation: trees can’t extrapolate, so model differences or ratios
  • Tiny datasets where a statistical model is enough

Key settings

SettingWhat it controlsTypical value
iterations / learning_rateNumber of trees and shrinkage500–2000 / 0.02–0.1
depthDepth of symmetric trees4–8
cat_featuresColumns to treat as categoricalIDs, calendar fields
loss_functionObjectiveRMSE, MAE, Quantile:alpha=0.9

Python example

✓ Tested: runs end to endDownload catboost_forecast.py
import numpy as np
import pandas as pd
from catboost import CatBoostRegressor

URL = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/airline-passengers.csv"
y = pd.read_csv(URL, index_col="Month", parse_dates=True)["Passengers"].asfreq("MS")

# trees can't extrapolate a trend, so model the year-on-year log growth instead of the level
growth = np.log(y).diff(12)
X = pd.DataFrame({f"lag{k}": growth.shift(k) for k in (1, 2, 3, 12)})
X["month"] = y.index.month.astype(str)            # categorical: CatBoost encodes it itself
data = X.assign(target=growth).dropna()
train, test = data.iloc[:-12], data.iloc[-12:]

model = CatBoostRegressor(iterations=600, depth=4, learning_rate=0.03, loss_function="RMSE",
                          cat_features=["month"], verbose=0, random_seed=0)
model.fit(train.drop(columns="target"), train["target"])

# one-step-ahead: turn predicted growth back into passengers using the value 12 months earlier
pred_growth = model.predict(test.drop(columns="target"))
forecast = y.shift(12).loc[test.index] * np.exp(pred_growth)
print(f"MAE: {np.mean(np.abs(y.loc[test.index] - forecast)):.1f}")
print(dict(zip(model.feature_names_, model.get_feature_importance().round(1).tolist())))

Tips & pitfalls

  • Model growth or differences (as in the example) so the trees never need to extrapolate.
  • Use loss_function='Quantile:alpha=…' or 'MultiQuantile' for prediction intervals.
  • For multi-step forecasts, either predict recursively or train one model per horizon.

References

  1. Prokhorenkova, L., Gusev, G., Vorobev, A., Dorogush, A. V., & Gulin, A. (2018). CatBoost: unbiased boosting with categorical features. Advances in Neural Information Processing Systems 31.
  2. Dorogush, A. V., Ershov, V., & Gulin, A. (2018). CatBoost: gradient boosting with categorical features support. arXiv:1810.11363.