我正在寻找一种在 sklearn中绘制图表cv_results_
的方法。GridSearchCV
但是示例中的代码使用了grid_scores_
n_topics = [10, 15, 20, 25, 30]
log_likelyhoods_5 = [round(gscore.mean_validation_score) for gscore in
model.grid_scores_ if gscore.parameters['learning_decay']==0.5]
log_likelyhoods_7 = [round(gscore.mean_validation_score) for gscore in
model.grid_scores_ if gscore.parameters['learning_decay']==0.7]
log_likelyhoods_9 = [round(gscore.mean_validation_score) for gscore in
model.grid_scores_ if gscore.parameters['learning_decay']==0.9]
我改变grid_scores_
了cv_results
results = pd.DataFrame(model.cv_results_)
og_likelyhoods_5 = [round(results['mean_test_score'][gscore]) for gscore in
results['params'] if results['params'][gscore]['learning_decay']==0.5]
log_likelyhoods_7 = [round(results['mean_test_score'][gscore]) for gscore in
results['params'] if results['params'][gscore]['learning_decay']==0.7]
log_likelyhoods_9 = [round(results['mean_test_score'][gscore]) for gscore in
results['params'] if results['params'][gscore]['learning_decay']==0.9]
cv_results
包括 ['params']
0 {'learning_decay': 0.5, 'n_components': 10}
1 {'learning_decay': 0.5, 'n_components': 15}
2 {'learning_decay': 0.5, 'n_components': 20}
3 {'learning_decay': 0.5, 'n_components': 25}
4 {'learning_decay': 0.5, 'n_components': 30}
5 {'learning_decay': 0.7, 'n_components': 10}
6 {'learning_decay': 0.7, 'n_components': 15}
7 {'learning_decay': 0.7, 'n_components': 20}
8 {'learning_decay': 0.7, 'n_components': 25}
9 {'learning_decay': 0.7, 'n_components': 30}
10 {'learning_decay': 0.9, 'n_components': 10}
11 {'learning_decay': 0.9, 'n_components': 15}
12 {'learning_decay': 0.9, 'n_components': 20}
13 {'learning_decay': 0.9, 'n_components': 25}
14 {'learning_decay': 0.9, 'n_components': 30}
我有错误
Traceback (most recent call last):
File "finallda.py", line 134, in <module>
log_likelyhoods_5 = [round(results['mean_test_score'][gscore]) for gscore
in len(results['params']) if results['params'][gscore]
['learning_decay']==0.5]
KeyError: "None of [['learning_decay', 'n_components']] are in the [index]"
我必须提取['mean_test_score']
良好的条件:
gscore.parameters['learning_decay']==0.5
gscore.parameters['learning_decay']==0.7
gscore.parameters['learning_decay']==0.9