4

我正在尝试classifierobject.cv_result_GridSearchCV使用 5 折交叉验证的方法中获取平均火车分数,但它*** KeyError: 'mean_train_score'在 Google Colab 中给了我。sklearn但是,相同的代码在 0.19.1版本的本地机器 Ipython 笔记本中运行良好。谁能帮助我如何在 google colab 中获得输出?

clf.cv_results_.keys()输出如下 -

对于我的本地笔记本 -

dict_keys(['mean_fit_time', 'std_fit_time', 'mean_score_time', 'std_score_time', 'param_n_neighbors', 'params', 'split0_test_score', 'split1_test_score', 'split2_test_score', 'split3_test_score', 'split4_test_score', 'mean_test_score', 'std_test_score', 'rank_test_score', 'split0_train_score', 'split1_train_score', 'split2_train_score', 'split3_train_score', 'split4_train_score', 'mean_train_score', 'std_train_score'])

在谷歌 colab 笔记本上 -

dict_keys(['mean_fit_time', 'std_fit_time', 'mean_score_time', 'std_score_time', 'param_n_neighbors', 'params', 'split0_test_score', 'split1_test_score', 'split2_test_score', 'split3_test_score', 'split4_test_score', 'mean_test_score', 'std_test_score', 'rank_test_score'])

谷歌colab在哪里mean_train_score。我错过了什么吗?

from sklearn.model_selection import GridSearchCV

neigh = KNeighborsClassifier(n_jobs=-1)
parameters = {'n_neighbors':[1, 5, 10, 15, 19 , 21, 31, 41, 51]}
clf = GridSearchCV(neigh, parameters, cv=5,\ 
                   scoring='roc_auc',n_jobs=-1) 
clf.fit(x_train, y_train)
train_auc= clf.cv_results_['mean_train_score']
train_auc_std= clf.cv_results_['std_train_score']
cv_auc = clf.cv_results_['mean_test_score'] 
cv_auc_std= clf.cv_results_['std_test_score']

4

1 回答 1

16

尝试return_train_score=True在里面设置GridSearchCV()来计算火车分数(默认情况下是关闭的,请参阅文档)。sklearn也许您在某个局部集合中有某种全局变量。

于 2019-07-22T05:27:40.157 回答