[python] Keep the first iteration when an sklearn iteration_range ends at 0 #12790
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.35) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.35 · 174 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.309
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12790"
general
weight: 0.35
RAMitchell
XGBRegressor.predict(X, iteration_range=(5, 0))returns the prediction from every tree.Booster.predictandinplace_predictwith the same range use trees 5 onward, since an end of 0 means "up to the last round" there._get_iteration_rangetreats any range that ends in 0 as the default and swaps it for(0, best_iteration + 1)or(0, 0), so the first iteration gets dropped without a warning. It's the same on master and on 3.4.1.predict_probaandapplygo through the same helper, and so do the dask estimators.The fix keeps the first iteration and only fills in the end. An end of 0 still means
best_iteration + 1after early stopping, the way theearly_stopping_roundsdocs describe it. A first iteration past that end now hits the booster's owntree_begin <= tree_endcheck, the same error you'd get passing(11, 10)directly.applywith a nonzero first iteration now raises the booster's "Predict leaf supports only iteration end" error instead of quietly returning every leaf, which is the one behavior change worth calling out.The new test sits next to
test_best_iteration. It checks that(begin, 0)matches(begin, end)forpredictandpredict_proba, with and without early stopping, and thatapplyraises like the booster does. Both cases fail on master and pass with the fix, and the rest oftests/python/test_with_sklearn.pystill passes.