Skip to content

Commit

Permalink
Address reviewer's comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Oct 8, 2021
1 parent 19df698 commit 75e6c4e
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions python-package/xgboost/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 75e6c4e

Please sign in to comment.