diff --git a/python-package/xgboost/training.py b/python-package/xgboost/training.py index e07bab87cf18..b36e75d3a163 100644 --- a/python-package/xgboost/training.py +++ b/python-package/xgboost/training.py @@ -11,7 +11,7 @@ from . import callback -def _is_new_callback(callbacks: Optional[List[callback.TrainingCallback]]) -> None: +def _assert_new_callback(callbacks: Optional[List[callback.TrainingCallback]]) -> None: is_new_callback: bool = not callbacks or all( isinstance(c, callback.TrainingCallback) for c in callbacks ) @@ -40,14 +40,14 @@ def _train_internal(params, dtrain, start_iteration = 0 - _is_new_callback(callbacks) + _assert_new_callback(callbacks) if verbose_eval: verbose_eval = 1 if verbose_eval is True else verbose_eval callbacks.append(callback.EvaluationMonitor(period=verbose_eval)) if early_stopping_rounds: - callbacks.append(callback.EarlyStopping( - rounds=early_stopping_rounds, maximize=maximize - )) + callbacks.append( + callback.EarlyStopping(rounds=early_stopping_rounds, maximize=maximize) + ) callbacks = callback.CallbackContainer(callbacks, metric=feval) bst = callbacks.before_training(bst) @@ -445,15 +445,17 @@ def cv(params, dtrain, num_boost_round=10, nfold=3, stratified=False, folds=None # setup callbacks callbacks = [] if callbacks is None else callbacks - _is_new_callback(callbacks) + _assert_new_callback(callbacks) if isinstance(verbose_eval, bool) and verbose_eval: verbose_eval = 1 if verbose_eval is True else verbose_eval - callbacks.append(callback.EvaluationMonitor(period=verbose_eval, - show_stdv=show_stdv)) + callbacks.append( + callback.EvaluationMonitor(period=verbose_eval, show_stdv=show_stdv) + ) if early_stopping_rounds: - callbacks.append(callback.EarlyStopping( - rounds=early_stopping_rounds, maximize=maximize)) + callbacks.append( + callback.EarlyStopping(rounds=early_stopping_rounds, maximize=maximize) + ) callbacks = callback.CallbackContainer(callbacks, metric=feval, is_cv=True) booster = _PackedBooster(cvfolds)