8000 [MRG] Model selection documentation by raghavrv · Pull Request #4 · raghavrv/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG] Model selection documentation #4

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next 10000 Next commit
BF: FIX OvR decision_function_shape in SVC
  • Loading branch information
dohmatob authored and amueller committed Oct 23, 2015
commit 5427e0874e8e1d50c20587d3fb2c8dbb2d972b06
2 changes: 1 addition & 1 deletion sklearn/svm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ def decision_function(self, X):
"change from 'ovo' to 'ovr' in 0.18. This will change "
"the shape of the decision function returned by "
"SVC.", ChangedBehaviorWarning)
if self.decision_function_shape == 'ovr':
if self.decision_function_shape == 'ovr' and len(self.classes_) > 2:
return _ovr_decision_function(dec < 0, dec, len(self.classes_))
return dec

Expand Down
11 changes: 11 additions & 0 deletions sklearn/svm/tests/test_svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from sklearn.exceptions import ConvergenceWarning
from sklearn.exceptions import NotFittedError

from sklearn.multiclass import OneVsRestClassifier

# toy sample
X = [[-2, -1], [-1, -1], [-1, -2], [1, 1], [1, 2], [2, 1]]
Y = [1, 1, 1, 2, 2, 2]
Expand Down Expand Up @@ -852,3 +854,12 @@ def test_hasattr_predict_proba():
assert_true(hasattr(G, 'predict_proba'))
msg = "predict_proba is not available when fitted with probability=False"
assert_raise_message(NotFittedError, msg, G.predict_proba, iris.data)


def test_decision_function_shape_two_class():
for n_classes in [2, 3]:
X, y = make_blobs(centers=n_classes, random_state=0)
for estimator in [svm.SVC, svm.NuSVC]:
clf = OneVsRestClassifier(estimator(
decision_function_shape="ovr")).fit(X, y)
assert_equal(len(clf.predict(X)), len(y))
0