Skip to content

xgboost/native-predict-after-early-stopping

Rule native-predict-after-early-stopping
Pack XGBoost
Severity warning
Fix none, edit by hand
Library versions every version

XGBoost's native Booster.predict and Booster.inplace_predict use all retained rounds by default, including any rounds after early stopping found the best validation score. The scikit-learn estimators use the best round automatically.

model = xgb.train(params, train, evals=[(valid, "valid")], early_stopping_rounds=5)
predictions = model.predict(test)
predictions = model.predict(test, iteration_range=(0, model.best_iteration + 1))

The rule follows a native booster from a train call with a positive integer literal for early_stopping_rounds, including hexadecimal, octal and binary integers. An empty callback list still lets XGBoost create the early stopping callback. The rule checks each prediction method's keyword and positional forms for iteration_range. Nonempty callbacks and unpacked arguments can change the behavior and are outside this check.

Pass iteration_range=(0, model.best_iteration + 1) for best-round predictions. The upper end is exclusive. For tree boosters, EarlyStopping(save_best=True) can discard later rounds during training. Use iteration_range=(0, 0) to request all retained rounds explicitly.

Early stopping and prediction

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

Native XGBoost prediction uses all retained rounds after early stopping. To predict at the best round, pass iteration_range=(0, $MODEL.best_iteration + 1).

Browse the other rules of the XGBoost pack.