Support min_delta in early stopping. (#7137)

* Support `min_delta` in early stopping.

* Remove abs_tol.
This commit is contained in:
Jiaming Yuan
2021-08-03 14:29:17 +08:00
committed by GitHub
parent 7bdedacb54
commit e2c406f5c8
2 changed files with 31 additions and 23 deletions

View File

@@ -126,26 +126,30 @@ class TestCallbacks:
assert len(dump) - booster.best_iteration == early_stopping_rounds + 1
assert len(early_stop.stopping_history['Train']['CustomErr']) == len(dump)
# test tolerance, early stop won't occur with high tolerance.
tol = 10
rounds = 100
early_stop = xgb.callback.EarlyStopping(
rounds=early_stopping_rounds,
metric_name='CustomErr',
data_name='Train',
abs_tol=tol
min_delta=100,
save_best=True,
)
booster = xgb.train(
{'objective': 'binary:logistic',
'eval_metric': ['error', 'rmse'],
'tree_method': 'hist'}, D_train,
{
'objective': 'binary:logistic',
'eval_metric': ['error', 'rmse'],
'tree_method': 'hist'
},
D_train,
evals=[(D_train, 'Train'), (D_valid, 'Valid')],
feval=tm.eval_error_metric,
num_boost_round=rounds,
callbacks=[early_stop],
verbose_eval=False)
# 0 based index
assert booster.best_iteration == rounds - 1
verbose_eval=False
)
# No iteration can be made with min_delta == 100
assert booster.best_iteration == 0
assert booster.num_boosted_rounds() == 1
def test_early_stopping_skl(self):
from sklearn.datasets import load_breast_cancer