optuna_integration.CatBoostPruningCallback
- class optuna_integration.CatBoostPruningCallback(trial, metric, eval_set_index=None)[source]
Callback for catboost to prune unpromising trials.
See the example if you want to add a pruning callback which observes validation accuracy of a CatBoost model.
Note
optuna.TrialPruned
cannot be raised inafter_iteration()
that is called in CatBoost viaCatBoostPruningCallback
. You must callcheck_pruned()
after training manually unlike other pruning callbacks to raiseoptuna.TrialPruned
.Note
This callback cannot be used with CatBoost on GPUs because CatBoost doesn’t support a user-defined callback for GPU. Please refer to CatBoost issue.
- Parameters:
trial (optuna.trial.Trial) – A
Trial
corresponding to the current evaluation of the objective function.metric (str) – An evaluation metric for pruning, e.g.,
Logloss
andAUC
. Please refer to CatBoost reference for further details.eval_set_index (int | None) – The index of the target validation dataset. If you set only one
eval_set
,eval_set_index
is None. If you set multiple datasets aseval_set
, the index ofeval_set
must beeval_set_index
, e.g.,0
or1
wheneval_set
contains two datasets.
Note
Added in v3.0.0 as an experimental feature. The interface may change in newer versions without prior notice. See https://github.com/optuna/optuna/releases/tag/v3.0.0.
Methods
after_iteration
(info)Report an evaluation metric value for Optuna pruning after each CatBoost's iteration.
Raise
optuna.TrialPruned
manually if the CatBoost optimization is pruned.- after_iteration(info)[source]
Report an evaluation metric value for Optuna pruning after each CatBoost’s iteration.
This method is called by CatBoost.
- Parameters:
info (Any) – A
SimpleNamespace
containing iteraion,validation_name
,metric_name
and history of losses. For exampleSimpleNamespace(iteration=2, metrics={ 'learn': {'Logloss': [0.6, 0.5]}, 'validation': {'Logloss': [0.7, 0.6], 'AUC': [0.8, 0.9]} })
.- Returns:
A boolean value. If
False
, CatBoost internally stops the optimization with Optuna’s pruning logic without raisingoptuna.TrialPruned
. Otherwise, the optimization continues.- Return type: