Python AttributeError: 'GridSearchCV' 对象没有属性 'cv_results_'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41524565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AttributeError: 'GridSearchCV' object has no attribute 'cv_results_'
提问by Cox Tox
I try to apply this code :
我尝试应用此代码:
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)
But I have this error :
但我有这个错误:
AttributeError: 'GridSearchCV' object has no attribute 'cv_results_'
采纳答案by Cox Tox
Solved ! Uninstall and install conda scikit learnin 0.18.1 How to upgrade scikit-learn package in anaconda.
解决了 !在 0.18.1 中卸载并安装conda scikit learn如何升级 anaconda 中的 scikit-learn 包。
When I import GridSearch :
当我导入 GridSearch 时:
from sklearn.model_selection import GridSearchCV
回答by lejlot
Update your scikit-learn, cv_results_
has been introduced in 0.18.1, earlier it was called grid_scores_
and had slightly different structure http://scikit-learn.org/0.17/modules/generated/sklearn.grid_search.GridSearchCV.html#sklearn.grid_search.GridSearchCV
更新您的 scikit-learn,cv_results_
已在 0.18.1 中引入,较早时被调用grid_scores_
且结构略有不同http://scikit-learn.org/0.17/modules/generated/sklearn.grid_search.GridSearchCV.html#sklearn.grid_search .GridSearchCV
回答by Yatin Arora
from sklearn.model_selection import GridSearchCV
从 sklearn.model_selection 导入 GridSearchCV
use this clf.cv_results_
用这个 clf.cv_results_
回答by Janderson FFerreira
First, you should update your scklearn, using:
首先,您应该使用以下命令更新您的 scklearn:
pip install -U scikit-learn
After that, check if you are include the wrong module:
之后,检查您是否包含错误的模块:
from sklearn.grid_search import GridSearchCV
Change to new path:
更改为新路径:
from sklearn.model_selection import GridSearchCV
(this is the right way)
(这是正确的方法)