-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[MRG + 3] OneVsRestClassifier: don't expose predict_proba and decision_function if base estimator doesn't support them #7812
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
methods if they are not supported by base estimator.
decision_only = OneVsRestClassifier(svm.SVR()).fit(X_train, Y_train) | ||
assert_raises(AttributeError, decision_only.predict_proba, X_test) | ||
assert not hasattr(decision_only, 'predict_proba') |
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.
these are pytest style asserts, while we are still using nosetests. Maybe use "assert_true" and "assert_false" until we transition?
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.
a good point; it seems I got too used to pytest asserts :)
I'm +1 for this change and it LGTM. |
@jnothman a nice catch; I thought about a fallback when writing this PR, but failed to come up with an example where checking self.estimator doesn't work. I'll fix that. |
Does it look better now? |
+1 for 0.18.1 as this is kind of a bug fix right? |
|
||
# Estimator which can get predict_proba enabled after fitting | ||
gs = GridSearchCV(svm.SVC(probability=False), | ||
param_grid={'probability': [True]}) |
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.
Thanks for testing this.
Thanks @kmike |
…n_function if base estimator doesn't support them (scikit-learn#7812) * OneVsRestClassifier: don't expose predict_proba and decision_function methods if they are not supported by base estimator. * TST use nose-style asserts * handle a case where classifier get predict_proba method only after .fit
…n_function if base estimator doesn't support them (scikit-learn#7812) * OneVsRestClassifier: don't expose predict_proba and decision_function methods if they are not supported by base estimator. * TST use nose-style asserts * handle a case where classifier get predict_proba method only after .fit
…n_function if base estimator doesn't support them (scikit-learn#7812) * OneVsRestClassifier: don't expose predict_proba and decision_function methods if they are not supported by base estimator. * TST use nose-style asserts * handle a case where classifier get predict_proba method only after .fit
…n_function if base estimator doesn't support them (scikit-learn#7812) * OneVsRestClassifier: don't expose predict_proba and decision_function methods if they are not supported by base estimator. * TST use nose-style asserts * handle a case where classifier get predict_proba method only after .fit
…n_function if base estimator doesn't support them (scikit-learn#7812) * OneVsRestClassifier: don't expose predict_proba and decision_function methods if they are not supported by base estimator. * TST use nose-style asserts * handle a case where classifier get predict_proba method only after .fit
Currently OneVsRestClassifier has predict_proba and decision_function methods even if base estimator doesn't have them. This makes it harder to check if an estimator supports predict_proba or not because it is not enough to run
hasattr(estimator, 'predict_proba')
, one have to special-case OneVsRestClassifier.In this PR it is changed, so that OneVsRestClassifier is more similar to Pipeline: if base estimator doesn't provide predit_proba or decision_function then OneVsRestClassifier also doesn't provide them.
It is not 100% backwards compatible: AttributeError is raised earlier, on ovr.decision_function / ovr.predict_proba access, not when these methods are called.