Skip to content

MNT Make sample_weight checking more consistent in regression metrics #30886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

lucyleeow
Copy link
Member

Reference Issues/PRs

Ref: #30787 (comment)

What does this implement/fix? Explain your changes.

_check_reg_targets will now perform check_consistent_length on sample_weight as well as y_true and y_pred as well as _check_sample_weight

  • this means that all array checks are done _check_reg_targets, which means all checks are at the start and means we know who is raising errors relating to inputs
  • only 2 metrics performed _check_sample_weight but AFAICT other metrics that accept sample_weight would also benefit from this check

Any other comments?

Not sure of what extra tests to add as _check_sample_weight and check_consistent_length are both tested separately, and it seems redundant to check those again in the context of _check_reg_targets.

I guess I could try a few different inputs and check that the result is the same as what _check_sample_weight gives ?

cc @ogrisel

Copy link

github-actions bot commented Feb 24, 2025

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 85a39ee. Link to the linter CI: here

@ogrisel
Copy link
Member

ogrisel commented Feb 24, 2025

@lucyleeow there are broken tests with older versions of numpy. Can you please take a look?

@lucyleeow
Copy link
Member Author

@ogrisel welp the tests now pass and the CI workflows are so old I can't see them, so I don't know what the previous failure was exactly.

Are you happy with the status @ogrisel or ?

I am not sure this requires a changelog entry. Technically we are adding _check_sample_weight to some metrics, which previously did not have this check. AFAICT the additional checks that users would affect users would be:

  • sample_weight can only be 1D or scalar
  • sample_weight cannot be negative

I can add changelogs to all metrics where we added _check_sample_weight to explain the additional checking?

@lucyleeow
Copy link
Member Author

@ogrisel gentle ping 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants