xgboost/sample-weight-without-eval-weight
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| XGBoost | warning | none, edit by hand | All versions |
Passing sample_weight to XGBoost estimator fit() weights training gradients and Hessians, while eval_set entries are scored unweighted unless sample_weight_eval_set is also passed. Early stopping and validation curves then optimize a different loss than training.
model.fit( X_train, y_train, sample_weight=w_train, eval_set=[(X_val, y_val)],)model.fit( X_train, y_train, sample_weight=w_train, eval_set=[(X_val, y_val)], sample_weight_eval_set=[w_val],)What the rule reports
Section titled “What the rule reports”Calls to fit() on an XGBoost scikit-learn estimator (XGBRegressor, XGBClassifier, XGBRanker, XGBRFRegressor, XGBRFClassifier, or XGBModel) that pass a non-None sample_weight together with a non-None eval_set without a non-None sample_weight_eval_set.
How to fix it
Section titled “How to fix it”Pass sample_weight_eval_set=[w_val] (one weight array per eval_set tuple in the same order) so validation metrics and early stopping match the weighted training objective.
Diagnostic message
Section titled “Diagnostic message”fit() passes sample_weight for training without sample_weight_eval_set, so validation loss and early stopping are evaluated unweighted. Pass sample_weight_eval_set with one weight array per eval_set entry.See all rules in the XGBoost pack.