-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5ef4b2e
fix OVR classifier edgecase bugs
amueller 3b675d1
add regression tests for OVO and OVR decision function shapes
amueller 346aa4b
add whatsnew entry
amueller f031817
make test of decision_function conditional on whether there's a decis…
amueller 4998777
gah fix indentation
amueller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,)) | ||
|
||
if test_predict_proba: | ||
X_test = np.array([[0, 0, 4]]) | ||
|
@@ -524,6 +527,12 @@ def test_ovo_decision_function(): | |
n_samples = iris.data.shape[0] | ||
|
||
ovo_clf = OneVsOneClassifier(LinearSVC(random_state=0)) | ||
# first binary | ||
ovo_clf.fit(iris.data, iris.target == 0) | ||
decisions = ovo_clf.decision_function(iris.data) | ||
assert_equal(decisions.shape, (n_samples,)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PEP8 here too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is pep8.... |
||
|
||
# then multi-class | ||
ovo_clf.fit(iris.data, iris.target) | ||
decisions = ovo_clf.decision_function(iris.data) | ||
|
||
|
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, lgtm then