#12612·xgboost

[python-package] Early stopping minimizes the higher-is-better metrics interval-regression-accuracy and ams@k when maximize is not set

Author: lucaluo925Created Sep 24, 2026Updated Sep 24, 2026

When maximize is not given, EarlyStopping infers the direction of the metric from a hard-coded list of prefixes (python-package/xgboost/callback.py, maximize_metrics in EarlyStopping._update_rounds: auc, aucpr, pre, map, ndcg and their @ forms). Two built-in metrics where higher is better are missing from that list:

  • interval-regression-accuracy (survival:aft), and
  • ams@k / ams (registered in src/metric/rank_metric.cc).

They are therefore minimized. With early_stopping_rounds, training stops after early_stopping_rounds + 1 rounds with best_iteration = 0 while the validation metric is still improving. This affects xgb.train, xgb.cv and the sklearn estimators whenever maximize is not set explicitly.

AI disclosure: I found this with the help of an AI assistant (Claude), which also ran the reproduction below and drafted this issue; I reviewed it before posting.

Reproduce

python
# EarlyStopping auto-direction: higher-is-better built-in metrics
# 'interval-regression-accuracy' and 'ams@k' are MINIMIZED when maximize=None.
import numpy as np, xgboost as xgb
print("xgboost", xgb.__version__)
rng = np.random.default_rng(0)
n = 2000
X = rng.normal(size=(n, 5))
t = np.exp(X[:, 0] + 0.5 * X[:, 1] + rng.normal(scale=0.3, size=n))
lo, hi = t * 0.8, t * 1.25
d = xgb.DMatrix(X[:1500]); d.set_float_info("label_lower_bound", lo[:1500]); d.set_float_info("label_upper_bound", hi[:1500])
v = xgb.DMatrix(X[1500:]); v.set_float_info("label_lower_bound", lo[1500:]); v.set_float_info("label_upper_bound", hi[1500:])
params = {"objective": "survival:aft", "eval_metric": "interval-regression-accuracy",
          "aft_loss_distribution": "normal", "aft_loss_distribution_scale": 1.0,
          "learning_rate": 0.1, "max_depth": 3, "seed": 0}
hist = {}
bst = xgb.train(params, d, 200, evals=[(v, "valid")], evals_result=hist,
                early_stopping_rounds=10, verbose_eval=False)
acc = hist["valid"]["interval-regression-accuracy"]
print("rounds run:", len(acc), "best_iteration:", bst.best_iteration, "best_score:", bst.best_score)
print("accuracy at best_iteration:", acc[bst.best_iteration], " max accuracy seen:", max(acc), "at iter", int(np.argmax(acc)))
print("first 12 accuracies:", [round(a, 3) for a in acc[:12]])
# explicit maximize=True for comparison
bst2 = xgb.train(params, d, 200, evals=[(v, "valid")], early_stopping_rounds=10,
                 maximize=True, verbose_eval=False)
print("with maximize=True -> best_iteration:", bst2.best_iteration, "best_score:", bst2.best_score)

# ams@k (binary classification, higher-is-better)
y = (X[:, 0] + rng.normal(scale=0.5, size=n) > 0).astype(int)
dt = xgb.DMatrix(X[:1500], y[:1500]); dv = xgb.DMatrix(X[1500:], y[1500:])
hist = {}
b3 = xgb.train({"objective": "binary:logistic", "eval_metric": "[email protected]", "seed": 0, "learning_rate": 0.1},
               dt, 200, evals=[(dv, "valid")], evals_result=hist, early_stopping_rounds=10, verbose_eval=False)
a = hist["valid"]["[email protected]"]
print("ams: rounds run:", len(a), "best_iteration:", b3.best_iteration, "best_score:", b3.best_score, "max seen:", max(a), "at", int(np.argmax(a)))

Output:

xgboost 3.2.0
rounds run: 11 best_iteration: 0 best_score: 0.14
accuracy at best_iteration: 0.14  max accuracy seen: 0.318 at iter 10
first 12 accuracies: [0.14, 0.154, 0.17, 0.178, 0.192, 0.218, 0.234, 0.25, 0.272, 0.31, 0.318]
with maximize=True -> best_iteration: 55 best_score: 0.524
ams: rounds run: 11 best_iteration: 0 best_score: 14.128288269042969 max seen: 14.622285842895508 at 2

Expected

With maximize=None, these metrics are maximized (same result as maximize=True: best_iteration=55, best_score=0.524 for the AFT example).

Suggested fix

Add "interval-regression-accuracy", "ams" and "ams@" to maximize_metrics (or, more robustly, let the native metric report its direction). Happy to open a PR with a test in tests/python/test_callback.py.

Environment

xgboost 3.2.0 (PyPI), numpy 2.4.6, Python 3.11.15, Linux. The relevant code in callback.py is unchanged on master (085dff4, 2026-09-24).