CatBoost
Categorical Boosting
Yandex's gradient boosting. Automatically handles categorical features.
Categorical Boosting
Yandex's gradient boosting. Automatically handles categorical features.
CatBoost (Categorical Boosting) is a gradient boosting library released as open source in 2017 by Yandex, a Russian search company. Together with XGBoost and LightGBM, it is one of the three major GBDT (Gradient Boosted Decision Trees) libraries, and it is specialized in handling categorical features.
CatBoost's biggest differentiator is that it handles categorical features automatically. Existing GBDT libraries required categorical features to be preprocessed with one-hot encoding or label encoding, but CatBoost converts categorical features into numerical values using a technique called Target Statistics while preventing Target Leakage.
In addition, CatBoost uses a proprietary algorithm called Ordered Boosting. Existing GBDT computes residuals and trains on the same data, which carries a risk of overfitting, but CatBoost shuffles the data order and separates the data used for training from the data used for prediction, thereby building a more generalized model.
In practice, CatBoost often wins tabular data competitions (Kaggle), and it is chosen especially when high performance is desired while reducing preprocessing time. It shows strengths in domains with many categorical features, such as financial risk modeling, recommendation systems, and CTR prediction.
# CatBoost를 사용한 분류 모델
from catboost import CatBoostClassifier, Pool
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, roc_auc_score
import pandas as pd
# 샘플 데이터 (범주형 특성 포함)
data = pd.DataFrame({
'age': [25, 30, 35, 40, 45, 50, 55, 60] * 100,
'gender': ['M', 'F', 'M', 'F', 'M', 'F', 'M', 'F'] * 100,
'city': ['Seoul', 'Busan', 'Seoul', 'Daegu', 'Busan', 'Seoul', 'Daegu', 'Busan'] * 100,
'income': [3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000] * 100,
'target': [0, 1, 0, 1, 1, 0, 1, 0] * 100
})
# 범주형 특성 지정
cat_features = ['gender', 'city']
# 학습/테스트 분리
X = data.drop('target', axis=1)
y = data['target']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# CatBoost Pool 생성 (범주형 특성 자동 처리)
train_pool = Pool(X_train, y_train, cat_features=cat_features)
test_pool = Pool(X_test, cat_features=cat_features)
# 모델 학습
model = CatBoostClassifier(
iterations=500,
learning_rate=0.05,
depth=6,
l2_leaf_reg=3,
verbose=100
)
model.fit(train_pool)
# 예측 및 평가
predictions = model.predict(test_pool)
probabilities = model.predict_proba(test_pool)[:, 1]
print(f"Accuracy: {accuracy_score(y_test, predictions):.4f}")
print(f"AUC-ROC: {roc_auc_score(y_test, probabilities):.4f}")
# 특성 중요도 확인
feature_importance = model.get_feature_importance()
for name, importance in zip(X.columns, feature_importance):
print(f"{name}: {importance:.2f}")
"In a loan screening model, there are more than 30 categorical features such as occupation group and residential area. Rather than preprocessing them, with CatBoost you only need to specify cat_features. You automatically get the effect of Target Encoding rather than label encoding, and leakage is also prevented."
"CatBoost's Ordered Boosting randomly shuffles the training data and, when predicting the current sample, computes residuals using only the preceding samples. This reduces prediction shift and mitigates overfitting."
"In CatBoost, if you set early_stopping_rounds, training stops automatically when the validation loss does not improve. Setting iterations to a large value and using early stopping is a good way to find the optimal number of iterations."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
If you do not specify cat_features, CatBoost misinterprets categorical features as numeric values. String types are detected automatically, but categorical features encoded as numbers (e.g., region codes) must be specified explicitly.
Because of Ordered Boosting, training time can be longer than with XGBoost or LightGBM. For large datasets, set task_type='GPU' or adjust the subsample parameter.
If a categorical feature has too many unique values (e.g., user ID), the Target Statistics calculation becomes unstable. In this case, consider hashing or embedding techniques first.