gpt4 book ai didi

python - 如何从 GridSearchCV 绘制 cv_results_ replacy grid_scores_ 图表?

转载 作者:行者123 更新时间:2023-11-30 09:43:21 28 4
gpt4 key购买 nike

我正在寻找一种在 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]

我要更改cv_results上的grid_scores_

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

最佳答案

我有点困惑,所以请举一个最小的例子。请显示您使用的示例。有效果吗?

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

失败的线路是这一行:

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

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

希望这有帮助!

关于python - 如何从 GridSearchCV 绘制 cv_results_ replacy grid_scores_ 图表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56084837/

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