如何从GridSearchCV中绘制简历结果回放网格分数?

2024-05-04 06:43:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我在寻找一种在sklearn中从GridSearchCV绘制cv_results_的方法。 但是示例中的代码使用了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

^{pr2}$

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

Tags: inlogforcomponentsmeanresultsgridlearning
1条回答
网友
1楼 · 发布于 2024-05-04 06:43:50

我有点困惑,所以请举一个最小的例子。请展示你使用的例子。有用吗?在

在回溯中我只看到一个步骤,所以错误不在库中,而是在代码中,对吗?在

失败的线路是:

og_likelyhoods_5 = [round(results['mean_test_score'][gscore]) for gscore in 
results['params'] if results['params'][gscore]['learning_decay']==0.5]

请将listcompremission(您在这里的一行中执行了几个步骤,这很复杂)展开到for循环中,以查看列表的确切外观以及缺少键的位置。在

希望这有帮助!在

相关问题 更多 >