Repository navigation
FIX scorer metadata routing - #35421
Open
BabaSanfour wants to merge 15 commits into
Open
BabaSanfour wants to merge 15 commits into
BabaSanfour wants to merge 15 commits into
Conversation
|
Thank you for opening your first pull request to scikit-learn! 🎉 To help get your contribution reviewed, please make sure that:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
Fixes #27977, built on top of #31654.
What does this implement/fix? Explain your changes.
With routing on, a scorer from
make_scorer/get_scoreronly received metadata for its score function. When it calledpredict,predict_probaordecision_functionon the estimator, it passed nothing. #31654 only changedcross_validate, so theGridSearchCV+Pipelinecase still got no metadata in transform at scoring time.the fix is a new helper
_get_scorer_routing(scorer, estimator)inmetrics/_scorer.pythatMetadataRouterwith a self-request for the score function;add_self_request, add +MethodMapping).Existing routers now use it instead of the bare scorer.
Introduce yourself
I am Hamza Abdelhedi, a PhD student at Mila, Quebec AI institute. I have been using sklearn regularly since years and now I am building a tool that uses functionalities for NeuroAI pipelines. I contributed to other packages like mne-tools and related packages.
AI usage disclosure
I used Opus5.5 for finding the issue in sklearn and it led me to the issue and open PR. I brainstormed ideas on how to fix the issue and it helped me identify other potential fixes to do. Code was generated by it and reviewed by me.
Any other comments?
We could also use a method on each scorer class (e.g.
scorer._get_metadata_routing(estimator)) instead of a module-level function that branches on isinstance. However I went for a function because scoring can be a plain user callable without such a method, so routers would still need a fallback. I also avoided changing the public get_metadata_routing() signature, or storing the estimator in the scorer: one is an API change, the other would mutate user callables.