pip install catboost★CPU + GPU support ship in one package.from catboost import CatBoostClassifier★Binary / multi-class classification.from catboost import CatBoostRegressor★Regression tasks.from catboost import CatBoostRankerLearning-to-rank (needs group_id).from catboost import Pool, cv★Native data container + cross-validation.catboost.__version__Check the installed version.
Pool(X, y, cat_features=[...])★Wraps features + labels + column roles.model.fit(X, y, cat_features=[...])★fit() also accepts raw arrays/DataFrames directly — a Pool isn't mandatory.Pool(X, y, weight=w)Per-object sample weights.Pool(X, y, group_id=g)Query/group ids for ranking losses.Pool(X, y, text_features=[...])Free-text columns get tokenized internally.pool.set_baseline(preds)Warm-start from another model's predictions.pool.get_feature_names()Inspect columns after loading.
cat_features=[idx, ...]★coreIndices or names. Never one-hot these yourself.one_hot_max_size=2Cardinality ≤ this → plain one-hot instead of stats.# Ordered Target StatisticsdefaultEncodes categories from past rows only — no leak.max_ctr_complexity=4Max categorical columns combined into new CTR features.text_features=[...]Free text → tokenizers + embeddings automatically.has_time=TrueKeep row order (time series) instead of random permutation.
iterations=1000★Number of trees; alias n_estimators.learning_rate=0.03★Unset → auto-picked from dataset size & iterations.depth=6★Oblivious tree depth; typical range 4–10.l2_leaf_reg=3.0L2 regularization on leaf values.loss_function='Logloss'★Sets the task; see the reference card below.random_seed=42Reproducible splits & permutations.random_strength=1Randomness added to split scores; guards overfitting.
model = CatBoostClassifier(**params)★Instantiate — no training happens yet.model.fit(X, y)★Trains in place; returns the fitted model.model.fit(train_pool, eval_set=val_pool)★Fit directly on Pool objects.model.fit(X, y, verbose=100)Print metrics every N iterations.model.fit(X, y, plot=True)Live training chart in Jupyter.CatBoostRanker(loss_function='YetiRank')Learning-to-rank variant.
eval_set=(X_val, y_val)★Validation data scored every iteration.early_stopping_rounds=50★Stop if no improvement for N rounds.use_best_model=True★Keep trees only up to the best iteration.use_best_model=Trueneeds eval_setSilently ignored without an eval_set.od_type='IncToDec'Default detector algorithm; pair with od_pval.model.get_best_iteration()Which tree count the detector settled on.
model.predict(X)★Class labels or regression values.model.predict_proba(X)★Class probabilities (classifier only).model.predict(X, prediction_type='RawFormulaVal')Raw score before sigmoid/softmax.model.score(X, y)Accuracy (clf) or R² (reg) shortcut.model.eval_metrics(pool, ['AUC'])Compute any metric post-hoc on a Pool.model.get_best_score()Best per-metric scores on eval_set.
model.get_feature_importance()★Default: PredictionValuesChange.model.feature_importances_Sklearn-style shortcut attribute.get_feature_importance(type='ShapValues')★Per-object, per-feature contributions.get_feature_importance(type='LossFunctionChange')Importance via metric degradation.model.plot_tree(tree_idx=0)Visualize a single oblivious tree.model.select_features(...)Built-in recursive feature elimination.
cv(pool, params, fold_count=5)★K-fold CV; returns per-iteration mean ± std.model.grid_search(param_grid, X, y)★Exhaustive search; auto-refits on the best combo.model.randomized_search(dists, X, y, n_iter=10)Sample a fixed number of settings instead.grid_search(..., cv=3, plot=True)Both searches accept a live Jupyter chart.
task_type='GPU'★Switch the whole run to GPU.devices='0:1'Pick specific GPU device ids.thread_count=-1Use all available CPU cores.border_count=254Splits per numeric feature — max quality on GPU.bootstrap_type='Bayesian'How object weights are sampled each iteration.
model.save_model('model.cbm')★Native format — fastest save/load.model.load_model('model.cbm')★Instantiate the class first, then load.model.save_model('m.onnx', format='onnx')Cross-platform inference format.model.save_model('m.json', format='json')Human-readable, for inspection/porting.save_model('m.mlmodel', format='coreml')Apple CoreML, for iOS deployment.
LoglossBinary classification (target is 0/1).MultiClassMore than two target classes.RMSE · MAE · QuantileRegression, by error shape wanted.YetiRank · PairLogitRanking — requires group_id.eval_metric='AUC'Metric to watch can differ from the loss optimized.