Skip to content

Problem with GridSearchCV for SVC: AttributeError: 'GridSearchCV' object has no attribute 'best_estimator_' #2976

@slegroux

Description

@slegroux

I have a problem when using the SVC model with optimized parameters by GridSearch for prediction. It tells me "GridSearchCV' object has no attribute 'best_estimator_'".
I have tried with scikit-learn 0.14 installed via PIP and scikit-learn 0.15 installed from source and obtained the same error.

Code snippet:

parameters = {'gamma': np.logspace(-10, -8, 30),'C': np.logspace(6, 7, 40)}
svm1=GridSearchCV(svm.SVC(), parameters, verbose=1, refit=False, cv=3, n_jobs=4).fit(X_train, y_train)
svm1.predict(X_test)

error message:

/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/grid_search.pyc in predict(self)
326 @Property
327 def predict(self):
--> 328 return self.best_estimator_.predict
329
330 @Property

AttributeError: 'GridSearchCV' object has no attribute 'best_estimator_'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions