Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX cross_validate with multimetric scoring returns the non-failed scorers results if there is a failing scorer #23101

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

Conversation

simonandras
Copy link
Contributor

@simonandras simonandras commented Apr 10, 2022

Reference Issues/PRs

Fixes #22969.

What does this implement/fix? Explain your changes.

In _scorer.py in the _MultimetricScorer class the __call__ method is updated. Now instead of raising an exception of a failing scorer it passes the exception to the scores to handle later.

In _validation.py in the _score function the exception is handled at the line 789, based on the suggestion of @thomasjpfan.

Any other comments?

Do we need a test for the one-failing scorer case for the cross_validate function?

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!

Do we need a test for the one-failing scorer case for the cross_validate function?

Yes we need to test the new behavior. One as a non-regression test for cross_validate and another one for _MultimetricScorer itself.

Note: Changing the behavior of _MultimetricScorer to not raise anymore may require updating some unit tests. This is okay since _MultimetricScorer is a private class.

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!

This PR still requires a non-regression test for the original issue and test to test the behavior of _MultimetricScorer returning a dictionary with exceptions.

@simonandras
Copy link
Contributor Author

simonandras commented Apr 18, 2022

Updated the test_cross_validate_failing_scorer to cover the failing and non-failing multimetric case (the case of the original issue). I think its better this way than writing a new test. @thomasjpfan what do you think about this?
Also added a new test for _MultimetricScorer returning a dictionary.

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an entry to the change log at doc/whats_new/v1.1.rst with tag |Fix|. Like the other entries there, please reference this pull request with :pr: and credit yourself (and other contributors if applicable) with :user:.

…s is controlled by the new bool parameter. The _score function is changed accordingly. The test for the _MultimetricScorer which tested the exception returning case is replaced with the test_multimetric_scorer_exception_handling test. The test_cross_validate_failing_scorer function needs no modification.
Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. I'm mostly okay with using a string to send the exception information back to the caller. Note other reviewers, may have a different opinion on the matter.

@simonandras
Copy link
Contributor Author

@thomasjpfan I do not understand the failing test. Do you know what is the issue there?

@thomasjpfan
Copy link
Member

Merging with main should fix the circleci issue.

@simonandras
Copy link
Contributor Author

@thomasjpfan how do you see, do we need any more modification to the changes?

@thomasjpfan
Copy link
Member

Assuming you ran this to set the remote url:

git remote add upstream [email protected]:scikit-learn/scikit-learn.git

you can update this PR to fix the circleci issue:

git checkout cross_validate__with_multiple_scorer_nan_issue
git fetch upstream
git merge upstream/main

@simonandras
Copy link
Contributor Author

Thank you, it wokred!

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the update! I am mostly on board with this. Let's see what other reviewers think.

if self._raise_exc:
raise e
else:
scores[name] = format_exc()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reviewers, a string is used to pass the information back to the caller.

@simonandras
Copy link
Contributor Author

@thomasjpfan could you please mark this as "waiting for review"?

@cmarmo cmarmo added Waiting for Second Reviewer First reviewer is done, need a second one! and removed Waiting for Reviewer labels Oct 20, 2022
@glemaitre glemaitre self-requested a review December 28, 2022 13:42
Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the changes that I requested are only about style, I merged them directly and put my +1.

I will merge when the CI turns green. Thanks @simonandras

@glemaitre glemaitre enabled auto-merge (squash) December 28, 2022 14:04
@glemaitre glemaitre merged commit d17d0f9 into scikit-learn:main Dec 28, 2022
jjerphan pushed a commit to jjerphan/scikit-learn that referenced this pull request Jan 3, 2023
…scorers results even if some fail (scikit-learn#23101)

Co-authored-by: Guillaume Lemaitre <[email protected]>
jjerphan pushed a commit to jjerphan/scikit-learn that referenced this pull request Jan 20, 2023
…scorers results even if some fail (scikit-learn#23101)

Co-authored-by: Guillaume Lemaitre <[email protected]>
jjerphan pushed a commit to jjerphan/scikit-learn that referenced this pull request Jan 20, 2023
…scorers results even if some fail (scikit-learn#23101)

Co-authored-by: Guillaume Lemaitre <[email protected]>
jjerphan pushed a commit to jjerphan/scikit-learn that referenced this pull request Jan 23, 2023
…scorers results even if some fail (scikit-learn#23101)

Co-authored-by: Guillaume Lemaitre <[email protected]>
adrinjalali pushed a commit that referenced this pull request Jan 24, 2023
…scorers results even if some fail (#23101)

Co-authored-by: Guillaume Lemaitre <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cross_validate with multiple scorers sets ALL results to nan after just one has errored
4 participants