我正在尝试在sklearn中的线性回归模型中完成网格搜索。我有以下代码:
from sklearn.linear_model import Ridge
from sklearn.cross_validation import train_test_split
from sklearn.grid_search import GridSearchCV
X_train, X_test, y_train, y_test = train_test_split(X, star, test_size = 0.33, random_state = 42)
alphas = np.array([100,10,1,0.1,0.01,0.001,0.0001,0])
Rmodel = Ridge()
grid = GridSearchCV(estimator=Rmodel, param_grid=dict(alphas=alphas))
gridfit = Rmodel.fit(X_train, y_train)
print(grid.best_score_)
print(grid.best_estimator_.alpha)
错误
File "nlp2.py", line 77, in <module>
print(grid.best_score_)
AttributeError: 'GridSearchCV' object has no attribute 'best_score_'
我是否忽视或遗漏了这里的任何必要步骤?谢谢!!