Skip to content

[WIP] Correct ducktyping of predict proba in GridSearchCV #4909

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
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions sklearn/grid_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def score(self, X, y=None):
ChangedBehaviorWarning)
return self.scorer_(self.best_estimator_, X, y)

@if_delegate_has_method(delegate='estimator')
@if_delegate_has_method(delegate='best_estimator_')
def predict(self, X):
"""Call predict on the estimator with the best found parameters.

Expand All @@ -431,7 +431,7 @@ def predict(self, X):
"""
return self.best_estimator_.predict(X)

@if_delegate_has_method(delegate='estimator')
@if_delegate_has_method(delegate='best_estimator_')
def predict_proba(self, X):
"""Call predict_proba on the estimator with the best found parameters.

Expand All @@ -447,7 +447,7 @@ def predict_proba(self, X):
"""
return self.best_estimator_.predict_proba(X)

@if_delegate_has_method(delegate='estimator')
@if_delegate_has_method(delegate='best_estimator_')
def predict_log_proba(self, X):
"""Call predict_log_proba on the estimator with the best found parameters.

Expand All @@ -463,7 +463,7 @@ def predict_log_proba(self, X):
"""
return self.best_estimator_.predict_log_proba(X)

@if_delegate_has_method(delegate='estimator')
@if_delegate_has_method(delegate='best_estimator_')
def decision_function(self, X):
"""Call decision_function on the estimator with the best found parameters.

Expand All @@ -479,7 +479,7 @@ def decision_function(self, X):
"""
return self.best_estimator_.decision_function(X)

@if_delegate_has_method(delegate='estimator')
@if_delegate_has_method(delegate='best_estimator_')
def transform(self, X):
"""Call transform on the estimator with the best found parameters.

Expand All @@ -495,7 +495,7 @@ def transform(self, X):
"""
return self.best_estimator_.transform(X)

@if_delegate_has_method(delegate='estimator')
@if_delegate_has_method(delegate='best_estimator_')
def inverse_transform(self, Xt):
"""Call inverse_transform on the estimator with the best found parameters.

Expand Down
1 change: 1 addition & 0 deletions sklearn/svm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ def predict(self, X):
# probabilities are not available depending on a setting, introduce two
# estimators.
def _check_proba(self):
check_is_fitted(self, 'support_')
if not self.probability or self.probA_.size == 0 or self.probB_.size == 0:
raise AttributeError("predict_proba is not available when fitted with"
" probability=False")
Expand Down