xgboost/reused-early-stopping-callback
| Rule | reused-early-stopping-callback |
|---|---|
| Pack | XGBoost |
| Severity | warning |
| Fix | none, edit by hand |
| Library versions | every version |
XGBoost's EarlyStopping callback stores training history and a count of
rounds without improvement. Reusing it can carry those values into a new fit
and stop that fit sooner than intended.
stop = xgb.callback.EarlyStopping(rounds=5)for params in parameter_grid: stop = xgb.callback.EarlyStopping(rounds=5) model = xgb.train(params, train, evals=[(valid, "valid")], callbacks=[stop])What the rule reports
Section titled “What the rule reports”The rule checks callback lists and tuples passed to train in the body of a
loop. It reports any EarlyStopping instance created immediately before
the loop that the loop reuses. A name rebound by the loop target can refer
to a different callback on each pass.
How to fix it
Section titled “How to fix it”Construct a fresh callback for each training run. Where a callback must be copied, copy the unused instance before any fit.
Training API and callback reuse
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
XGBoost EarlyStopping retains state from the previous fit when this loop reuses it. Create a fresh callback inside the loop before each train call.Browse the other rules of the XGBoost pack.