I have trained a classification model calling CatBoostClassifier.fit()
, also providing an eval_set
.
Now, how can I fetch the best value of the evaluation metric, and the number of iteration when it was achieved during training? I can plot the information by setting plot=True
in the call to fit()
, but how can I assign it to a variable?
I can do it when I train the model calling cv()
, as cv()
returns the wanted information. But CatBoostClassifier.fit()
doesn't return anything, accordingly to the documentation.
Here the snippet of code I am using to fit the model:
model = CatBoostClassifier(
random_seed=42,
logging_level='Silent',
eval_metric='Accuracy'
)
model.fit(X_train,
y_train,
cat_features=cat_features_idxs,
eval_set=(X_val, y_val),
plot=True
)
Here how I manage to fetch the wanted information, if I use cv()
instead:
cv_data = cv(Pool(X, y, cat_features = cat_features_idxs),
model.get_params(),
fold_count = 5,
plot=True)
print('Validation accuracy (best average among cross-validation folds) is {} obtained at step {}.'.format(np.max(cv_data['test-Accuracy-mean']), np.argmax(cv_data['test-Accuracy-mean'])))