gpt4 book ai didi

python - 属性错误: 'GridSearchCV' object has no attribute 'cv_results_'

转载 作者:行者123 更新时间:2023-11-30 08:24:24 48 4
gpt4 key购买 nike

我尝试应用此代码:

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_'

最佳答案

更新你的 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

关于python - 属性错误: 'GridSearchCV' object has no attribute 'cv_results_' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41524565/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com