You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
learning_curve with exploit_incremental_learning=True fails to compute training scores when sample_weight is provided #33283
Describe the bug and give evidence about its user-facing impact
When using learning_curve with exploit_incremental_learning=True and passing sample_weight
(or other parameters) to the scorer, the training scores for all training sizes except the final one are returned as NaN.
This happens because _incremental_fit_estimator pre-computes the training scores' parameters once for the full training set, but then attempts to use them for subsets of the training data. This causes a ValueError (consistent length mismatch) inside the scorer, which is silently caught and replaced with NaN.
This affects any user trying to evaluate learning curves incrementally while using weighted metrics or metadata-aware scorers.
Steps/Code to Reproduce
importnumpyasnpfromsklearn.datasetsimportmake_classificationfromsklearn.linear_modelimportSGDClassifierfromsklearn.model_selectionimportlearning_curvefromsklearn.metricsimportmake_scorer, accuracy_scoreimportsklearn# Enable metadata routing to pass sample_weight to scorersklearn.set_config(enable_metadata_routing=True)
X, y=make_classification(n_samples=100, n_features=5, random_state=42)
weights=np.ones(100)
scorer=make_scorer(accuracy_score).set_score_request(sample_weight=True)
train_sizes, train_scores, _=learning_curve(
SGDClassifier(), X, y,
train_sizes=[0.3, 0.6, 0.9],
cv=3,
exploit_incremental_learning=True,
scoring=scorer,
params={'sample_weight': weights}
)
print("Training scores (expecting no NaNs):")
print(train_scores)
Expected Results
The training scores should be successfully computed for all training sizes. Example: [[0.96 0.96 0.96], [0.94 0.94 0.94], [0.92 0.92 0.92]] (no NaN values).
@juanf-0gravity@StefanieSenger , has the issue been solved?, It has only been triaged now.
would like to make a pr for this, if any changes are yet to be made(intent to fix the bug was raised with the issue). thankyou.
the fit_params also aren't being subsetted properly for partial_fit batches inside the loop. That one's still up for grabs if you want to take it @atheendre130505!
On a different note, @atheendre130505: The reproducer code would not run without setting set_fit_request and set_partial_fit_request on SGDClassifier. In sklearn 1.8.0.dev0, too, you would have gotten an UnsetMetadataPassedError. How did you come across that issue?
@atheendre130505 it seems you've autogenerated this issue with some AI agents, and doesn't seem to be coming from a real usecase. This hurts us because it diverts energy and focus from other projects which actually impact many users.
@juanf-0gravity it seems your PR is also autogenerated and a complete fix. The PR was also opened before "Needs Triage" was removed, which shows you haven't read our contributing guidelines.
Activity
juanf-0gravity commentedon Feb 14, 2026
StefanieSenger commentedon Feb 15, 2026
Hi @atheendre130505, thanks for reporting.
This is indeed not only a bug, but two bugs (and at least one is my fault 😆).
Also, nice fix @juanf-0gravity. I've seen it too late.
atheendre130505 commentedon Feb 15, 2026
@juanf-0gravity @StefanieSenger , has the issue been solved?, It has only been triaged now.
would like to make a pr for this, if any changes are yet to be made(intent to fix the bug was raised with the issue). thankyou.
juanf-0gravity commentedon Feb 15, 2026
StefanieSenger commentedon Feb 15, 2026
I've addressed this already in ##33285.
Next steps are reviewing the two PRs.
StefanieSenger commentedon Feb 15, 2026
On a different note, @atheendre130505: The reproducer code would not run without setting
set_fit_requestandset_partial_fit_requestonSGDClassifier. In sklearn 1.8.0.dev0, too, you would have gotten anUnsetMetadataPassedError. How did you come across that issue?adrinjalali commentedon Feb 16, 2026
@atheendre130505 it seems you've autogenerated this issue with some AI agents, and doesn't seem to be coming from a real usecase. This hurts us because it diverts energy and focus from other projects which actually impact many users.
@juanf-0gravity it seems your PR is also autogenerated and a complete fix. The PR was also opened before "Needs Triage" was removed, which shows you haven't read our contributing guidelines.