Skip to content

[MRG+1] Ovr/OVO classifier decision_function shape fixes #9100

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

Merged
merged 5 commits into from
Jun 10, 2017

Conversation

amueller
Copy link
Member

OVR Classifier had a decision_function shape of (n_samples, 1) for binary classification, OVO classifier had (n_samples, 2) !
Fixed to conform to standard API.

@amueller amueller mentioned this pull request Jun 10, 2017
4 tasks
@amueller
Copy link
Member Author

Found via #8022.

@@ -574,6 +576,8 @@ def predict(self, X):
Predicted multi-class targets.
"""
Y = self.decision_function(X)
if self.n_classes_ == 2:
return self.classes_[(Y > 0).astype(np.int)]
Copy link
Member

Choose a reason for hiding this comment

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

This assumes that estimators_[0].decision_function correctly returns a vector. Are we relying on check_estimator to validate this, or should we check it here?

Copy link
Member Author

Choose a reason for hiding this comment

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

no we should assume that base_estimator actually works. Otherwise everything in sklearn is broken ;)

Copy link
Member

Choose a reason for hiding this comment

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

makes sense, lgtm then

@@ -251,6 +251,8 @@ def conduct_test(base_clf, test_predict_proba=False):
assert_equal(set(clf.classes_), classes)
y_pred = clf.predict(np.array([[0, 0, 4]]))[0]
assert_equal(set(y_pred), set("eggs"))
dec = clf.decision_function(X)
assert_equal(dec.shape, (5,))
Copy link
Member

Choose a reason for hiding this comment

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

PEP8: missing space after comma

# first binary
ovo_clf.fit(iris.data, iris.target == 0)
decisions = ovo_clf.decision_function(iris.data)
assert_equal(decisions.shape, (n_samples,))
Copy link
Member

Choose a reason for hiding this comment

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

PEP8 here too

Copy link
Member Author

Choose a reason for hiding this comment

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

this is pep8....

@GaelVaroquaux
Copy link
Member

LGTM. 👍

@GaelVaroquaux
Copy link
Member

Aside from the PEP8 issues :)

@agramfort
Copy link
Member

LGTM

+1 for merge when travis is happy

@agramfort agramfort changed the title [MRG] Ovr/OVO classifier decision_function shape fixes [MRG+1] Ovr/OVO classifier decision_function shape fixes Jun 10, 2017
@@ -251,6 +251,9 @@ def conduct_test(base_clf, test_predict_proba=False):
assert_equal(set(clf.classes_), classes)
y_pred = clf.predict(np.array([[0, 0, 4]]))[0]
assert_equal(set(y_pred), set("eggs"))
if hasattr(base_clf, 'decision_function'):
dec = clf.decision_function(X)
assert_equal(dec.shape, (5,))
Copy link
Member

Choose a reason for hiding this comment

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

this breaks travis, line needs to be indented deeper

@amueller
Copy link
Member Author

green! @vene?

@vene vene merged commit b43c791 into scikit-learn:master Jun 10, 2017
Sundrique pushed a commit to Sundrique/scikit-learn that referenced this pull request Jun 14, 2017
* fix OVR classifier edgecase bugs

* add regression tests for OVO and OVR decision function shapes
dmohns pushed a commit to dmohns/scikit-learn that referenced this pull request Aug 7, 2017
* fix OVR classifier edgecase bugs

* add regression tests for OVO and OVR decision function shapes
dmohns pushed a commit to dmohns/scikit-learn that referenced this pull request Aug 7, 2017
* fix OVR classifier edgecase bugs

* add regression tests for OVO and OVR decision function shapes
NelleV pushed a commit to NelleV/scikit-learn that referenced this pull request Aug 11, 2017
* fix OVR classifier edgecase bugs

* add regression tests for OVO and OVR decision function shapes
paulha pushed a commit to paulha/scikit-learn that referenced this pull request Aug 19, 2017
* fix OVR classifier edgecase bugs

* add regression tests for OVO and OVR decision function shapes
AishwaryaRK pushed a commit to AishwaryaRK/scikit-learn that referenced this pull request Aug 29, 2017
* fix OVR classifier edgecase bugs

* add regression tests for OVO and OVR decision function shapes
maskani-moh pushed a commit to maskani-moh/scikit-learn that referenced this pull request Nov 15, 2017
* fix OVR classifier edgecase bugs

* add regression tests for OVO and OVR decision function shapes
jwjohnson314 pushed a commit to jwjohnson314/scikit-learn that referenced this pull request Dec 18, 2017
* fix OVR classifier edgecase bugs

* add regression tests for OVO and OVR decision function shapes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants