Repository navigation
FIX Handle zero-weight samples in regression scores - #34798
aswanth-07 wants to merge 2 commits into
Conversation
|
Thank you for opening your first pull request to scikit-learn! 🎉 To help get your contribution reviewed, please make sure that:
|
|
Closing this PR after portfolio audit. scikit-learn's current contribution workflow requires an existing issue that is ready for development, while this PR explicitly has no reference issue. The implementation may be technically plausible, but the policy and demand gate is not met. Please re-file only after issue triage confirms scope. |
Reference Issues/PRs
No existing issue. I reproduced this on current
mainand found no matching open or closed issue or pull request.What does this implement/fix? Explain your changes.
Regression scores document that they are undefined for fewer than two samples, and scikit-learn's common metric contract treats zero-weight samples as equivalent to removing them. The existing guards counted the raw input length, so one nonzero-weight sample plus any number of zero-weight samples bypassed the guard. In particular,
d2_tweedie_scorecould then raiseZeroDivisionError, while the other affected scores returned a misleading finite value.This change counts nonzero sample weights after validation when deciding whether
r2_score,d2_tweedie_score, andd2_pinball_scorehave enough observations.d2_absolute_error_scoreinherits the corrected behavior throughd2_pinball_score. All four now follow the existing single-sample path: emitUndefinedMetricWarningand returnNaN.Validation:
python -m pytest sklearn/metrics/tests/test_regression.py -q— 33 passedSCIPY_ARRAY_API=1— 12 passed (optional backends skipped)Introduce yourself
I'm Aswanth. I focus on machine learning and deep learning and contribute bug fixes to scientific Python and ML libraries.
AI usage disclosure
I used AI assistance for:
Any other comments?
The permanent regression test fails for all four score functions on pristine
main;d2_tweedie_scorefails withZeroDivisionErrorand the others fail because they do not emit the documented warning.This pull request includes code written with the assistance of AI.
The code has not yet been reviewed by a human.