The Wayback Machine - https://web.archive.org/web/20220525095815/https://github.com/scikit-learn/scikit-learn/pull/22604
Skip to content
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

FIX Fixes OneVsOneClassifier.predict for Estimators with only predict_proba #22604

Merged
merged 4 commits into from Mar 18, 2022

Conversation

thomasjpfan
Copy link
Member

@thomasjpfan thomasjpfan commented Feb 24, 2022

Reference Issues/PRs

Fixes #13617

What does this implement/fix? Explain your changes.

This PR uses the correct threshold if the inner estimator uses predict_proba.

@thomasjpfan thomasjpfan added module:multiclass Quick Review labels Feb 24, 2022
@thomasjpfan
Copy link
Member Author

@thomasjpfan thomasjpfan commented Feb 25, 2022

Marking this as quick review. We do a very similar thing here:

if hasattr(self.estimators_[0], "decision_function") and is_classifier(
self.estimators_[0]
):
thresh = 0
else:
thresh = 0.5

Copy link
Contributor

@glemaitre glemaitre left a comment

LGTM

@thomasjpfan thomasjpfan changed the title FIX Fixes OneVsOneClassifier.predict for ests with only predict_proba FIX Fixes OneVsOneClassifier.predict for Estimators with only predict_proba Mar 2, 2022
Copy link
Member

@jjerphan jjerphan left a comment

Apart a suggestion, this LGTM. Thank you, @thomasjpfan.

if hasattr(self.estimators_[0], "decision_function") and is_classifier(
self.estimators_[0]
):
thresh = 0
else:
# predict_proba threshold
thresh = 0.5
return self.classes_[(Y > thresh).astype(int)]
Copy link
Member

@jjerphan jjerphan Mar 17, 2022

Choose a reason for hiding this comment

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

Is it worth wrapping this and the lines you mentioned, i.e.:

if hasattr(self.estimators_[0], "decision_function") and is_classifier(
self.estimators_[0]
):
thresh = 0
else:
thresh = 0.5

in a private _threshold property?

I think this can make the logic explicit and ease maintainability.

Copy link
Member Author

@thomasjpfan thomasjpfan Mar 17, 2022

Choose a reason for hiding this comment

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

OneVsOneClassifier and OneVsRestClassifier do not share a common base class where a _threshold property makes sense. Also the threshold is only used in the binary case.

Inspired by your suggestion, I think a helper function makes the logic better 7372cee (#22604)

@lesteve
Copy link
Member

@lesteve lesteve commented Mar 18, 2022

Merging main to get rid of the doc-min-dependencies error about Python 3.7.

@lesteve
Copy link
Member

@lesteve lesteve commented Mar 18, 2022

Merging, thanks!

@lesteve lesteve merged commit fb83577 into scikit-learn:main Mar 18, 2022
29 checks passed
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this issue Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:multiclass Quick Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants