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 in after_iteration() that is called in CatBoost via CatBoostPruningCallback. You must call check_pruned() after training manually unlike other pruning callbacks to raise optuna.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 (Trial) – A Trial corresponding to the current evaluation of the objective function.

  • metric (str) – An evaluation metric for pruning, e.g., Logloss and AUC. Please refer to CatBoost reference for further details.

  • eval_set_index (Optional[int]) – The index of the target validation dataset. If you set only one eval_set, eval_set_index is None. If you set multiple datasets as eval_set, the index of eval_set must be eval_set_index, e.g., 0 or 1 when eval_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.

check_pruned()

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 example SimpleNamespace(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 raising optuna.TrialPruned. Otherwise, the optimization continues.

Return type

bool

check_pruned()[source]

Raise optuna.TrialPruned manually if the CatBoost optimization is pruned.

Return type

None