本文介绍了AttributeError:"GridSearchCV"对象没有属性"cv_results_"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试应用此代码:
pipe = make_pipeline(TfidfVectorizer(min_df=5), LogisticRegression())
param_grid = {'logisticregression__C': [ 0.001, 0.01, 0.1, 1, 10, 100],
"tfidfvectorizer__ngram_range": [(1, 1),(1, 2),(1, 3)]}
grid = GridSearchCV(pipe, param_grid, cv=5)
grid.fit(text_train, Y_train)
scores = grid.cv_results_['mean_test_score'].reshape(-1, 3).T
# visualize heat map
heatmap = mglearn.tools.heatmap(
scores, xlabel="C", ylabel="ngram_range", cmap="viridis", fmt="%.3f",
xticklabels=param_grid['logisticregression__C'],
yticklabels=param_grid['tfidfvectorizer__ngram_range'])
plt.colorbar(heatmap)
但是我有这个错误:
AttributeError: 'GridSearchCV' object has no attribute 'cv_results_'
推荐答案
已解决!在0.18.1 conda scikit Learn " >如何在anaconda中升级scikit-learn软件包.
Solved !Uninstall and install conda scikit learn in 0.18.1 How to upgrade scikit-learn package in anaconda.
当我导入GridSearch时:
When I import GridSearch :
from sklearn.model_selection import GridSearchCV
这篇关于AttributeError:"GridSearchCV"对象没有属性"cv_results_"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!