Skip to main content

CatBoost and TensorFlow

CatBoost is not a Keras model and does not use TensorFlow callbacks. Its categorical statistics, ordered boosting, early stopping, and serialization belong to the CatBoost runtime.

Why the previous example was removed​

The former page downloaded data, shuffled it through tf.data, converted it back to NumPy, evaluated on training rows, and manually invoked Keras callbacks around repeated CatBoost fits. The callbacks could not select CatBoost trees or save a valid Keras model, and no test boundary existed.

Use CatBoost's native interface​

Pass a pandas DataFrame or Pool with explicit cat_features. In CatBoost 1.2.10, provide a training-only eval_set and early_stopping_rounds to CatBoost's fit, or configure its overfitting detector. use_best_model=True retains trees through the best validation iteration. Never use the final test partition as that validation set.

TensorFlow can learn representations for unstructured inputs before CatBoost. Select and freeze the encoder on training data, extract each split independently, and retain meaningful raw categorical columns if they remain useful. Refit the encoder within the outer fold whenever it participates in model selection.

Stacking and evaluation​

Train a meta-model only on out-of-fold CatBoost and TensorFlow predictions. In-sample base predictions expose fitted target information. Report ranking, probability quality, and thresholded decisions separately, and compare the hybrid with both standalone models under equal data and search budgets.

Deployment​

Bundle TensorFlow preprocessing and encoder weights with CatBoost's feature names, categorical indices, class order, and model artifact. Test unseen-category behavior and missing values at the interface.

Takeaway​

Use native CatBoost for tabular categorical learning. Add TensorFlow only for a real, independently validated neural stage—not as a data-loading detour or callback shim.