Scikit-learn: AttributeError: 'GridSearchCV' object has no attribute 'best_params_'

Created on 26 Jun 2014  ·  3Comments  ·  Source: scikit-learn/scikit-learn

Sorry, if this is the wrong place to post this. My code:

from sklearn import datasets, linear_model, cross_validation, grid_search
import numpy as np
digits = datasets.load_digits()
x = digits.data[:1000]
y = digits.target[:1000]
kf_total = cross_validation.KFold(len(x), n_folds=10, indices=True, shuffle=True, random_state=4)
lr = linear_model.LogisticRegression()
c_range = np.logspace(0, 4, 10)
lrgs = grid_search.GridSearchCV(estimator=lr, param_grid=dict(C=c_range), n_jobs=1)
results_lrgs = cross_validation.cross_val_score(lrgs, x, y, cv=kf_total, n_jobs=1)
print lrgs.best_params_

Error:

Traceback (most recent call last):
  File "cross.py", line 11, in <module>
    print lrgs.best_params_
AttributeError: 'GridSearchCV' object has no attribute 'best_params_'

What I'm missing?

Most helpful comment

You didn't call fit, right?
On Jun 26, 2014 4:36 PM, "Vitor Campos de Oliveira" <
[email protected]> wrote:

Sorry, if this is the wrong place to post this. My code:

from sklearn import datasets, linear_model, cross_validation, grid_search
import numpy as np
digits = datasets.load_digits()
x = digits.data[:1000]
y = digits.target[:1000]
kf_total = cross_validation.KFold(len(x), n_folds=10, indices=True,
shuffle=True, random_state=4)
lr = linear_model.LogisticRegression()
c_range = np.logspace(0, 4, 10)
lrgs = grid_search.GridSearchCV(estimator=lr, param_grid=dict(C=c_range),
n_jobs=1)
results_lrgs = cross_validation.cross_val_score(lrgs, x, y, cv=kf_total,
n_jobs=1)
print lrgs.best_params_

Error:

Traceback (most recent call last):
File "cross.py", line 11, in
print lrgs.best_params_
AttributeError: 'GridSearchCV' object has no attribute 'best_params_'

What I'm missing?


Reply to this email directly or view it on GitHub
https://github.com/scikit-learn/scikit-learn/issues/3320.

All 3 comments

You didn't call fit, right?
On Jun 26, 2014 4:36 PM, "Vitor Campos de Oliveira" <
[email protected]> wrote:

Sorry, if this is the wrong place to post this. My code:

from sklearn import datasets, linear_model, cross_validation, grid_search
import numpy as np
digits = datasets.load_digits()
x = digits.data[:1000]
y = digits.target[:1000]
kf_total = cross_validation.KFold(len(x), n_folds=10, indices=True,
shuffle=True, random_state=4)
lr = linear_model.LogisticRegression()
c_range = np.logspace(0, 4, 10)
lrgs = grid_search.GridSearchCV(estimator=lr, param_grid=dict(C=c_range),
n_jobs=1)
results_lrgs = cross_validation.cross_val_score(lrgs, x, y, cv=kf_total,
n_jobs=1)
print lrgs.best_params_

Error:

Traceback (most recent call last):
File "cross.py", line 11, in
print lrgs.best_params_
AttributeError: 'GridSearchCV' object has no attribute 'best_params_'

What I'm missing?


Reply to this email directly or view it on GitHub
https://github.com/scikit-learn/scikit-learn/issues/3320.

That's right. =\ I forgot the fit. Thank you Andreas.

How long will it take?

Was this page helpful?
0 / 5 - 0 ratings