CatBoost (Categorical Boosting) implementation.
Classes
CatBoost classifier with native support for categorical features.
__init__( self, iterations: int = 100, depth: int = 6, learning_rate: float = 0.03, l2_leaf_reg: float = 3.0, border_count: int = 128, bagging_temperature: float = 1.0, random_strength: float = 1.0, cat_features: Optional[List[int]] = None, verbose: bool = False, random_state: Optional[int] = None, )
Overview
The algorithm builds an ensemble of symmetric (oblivious) decision trees:
- Encode categorical features using ordered target statistics computed
- For each boosting iteration, compute the negative gradient of the
- Build a symmetric (oblivious) decision tree where all nodes at the
- Compute optimal leaf values with L2 regularization on the leaf weights
- Add the new tree to the ensemble, scaled by the learning rate
- Repeat until the specified number of iterations is reached
Theory
CatBoost addresses prediction shift (a form of target leakage in gradient boosting) through ordered boosting. For each sample x_i, the model M_i used to compute gradients is trained only on samples appearing before x_i in a random permutation \sigma.
The ordered target statistic for a categorical feature value c is:
where a is a prior weight and P is the prior value.
The regularized loss at iteration t is:
where \lambda is the L2 leaf regularization coefficient (l2_leaf_reg).
Parameters
iterations
depth
learning_rate
l2_leaf_reg
border_count
bagging_temperature
random_strength
cat_features
verbose
random_state
Attributes
model_
classes_
fit().
n_classes_
fit().
Notes
Complexity:
- Training: O(T \cdot n \cdot d \cdot D) where T = iterations,
- Prediction: O(T \cdot D) per sample (very fast due to oblivious trees)
- Datasets with categorical features that should not be one-hot encoded
- When minimal hyperparameter tuning is desired (strong defaults)
- When reducing prediction shift (target leakage) is important
- Production systems where fast inference with oblivious trees is beneficial
References
See Also
Train a CatBoost classifier with categorical feature support:
>>> from tuiml.algorithms.gradient_boosting import CatBoostClassifier
>>> import numpy as np
>>>
>>> X_train = np.array([[1, 0], [2, 1], [3, 0], [4, 1]])
>>> y_train = np.array([0, 1, 0, 1])
>>> clf = CatBoostClassifier(iterations=500, learning_rate=0.01)
>>> clf.fit(X_train, y_train)
>>> y_pred = clf.predict(X_train)
Methods
__repr__
(self) -> str
CatBoost regressor with native support for categorical features.
__init__( self, iterations: int = 100, depth: int = 6, learning_rate: float = 0.03, l2_leaf_reg: float = 3.0, border_count: int = 128, bagging_temperature: float = 1.0, random_strength: float = 1.0, cat_features: Optional[List[int]] = None, verbose: bool = False, random_state: Optional[int] = None, )
Overview
The regression variant follows the same ordered boosting procedure:
- Encode categorical features using ordered target statistics to
- For each iteration, compute the negative gradient of the loss
- Build a symmetric (oblivious) decision tree where all nodes at
- Compute optimal leaf values with L2 regularization
- Add the tree to the ensemble, scaled by the learning rate
- Repeat for the specified number of iterations
Theory
For the default RMSE objective, the loss for sample i is:
The ordered boosting scheme trains model M_i on a prefix of a random permutation \sigma to compute the gradient for sample x_{\sigma_i}:
The regularized leaf weight for leaf j is:
where \lambda is the l2_leaf_reg parameter.
Parameters
iterations
depth
learning_rate
l2_leaf_reg
border_count
bagging_temperature
random_strength
cat_features
verbose
random_state
Attributes
model_
Notes
Complexity:
- Training: O(T \cdot n \cdot d \cdot D) where T = iterations,
- Prediction: O(T \cdot D) per sample (very fast due to oblivious trees)
- Regression tasks with categorical features that should not be one-hot encoded
- When minimal hyperparameter tuning is desired (strong defaults)
- Datasets with mixed numerical and categorical features
- When fast inference with oblivious trees is needed in production
References
See Also
Train a CatBoost regressor with categorical feature support:
>>> from tuiml.algorithms.gradient_boosting import CatBoostRegressor
>>> import numpy as np
>>>
>>> X_train = np.array([[1, 0], [2, 1], [3, 0], [4, 1]])
>>> y_train = np.array([1.5, 3.5, 2.5, 4.5])
>>> reg = CatBoostRegressor(iterations=1000, depth=8)
>>> reg.fit(X_train, y_train)
>>> y_pred = reg.predict(X_train)
Methods
__repr__
(self) -> str