2 回答
TA贡献1808条经验 获得超4个赞
您必须迭代您的列表:
def get_values(res, k)
out = []
for v in res:
if k in v
out.append(v[k])
return out
out = get_values(results, 'test_f1_score')
或者单行:
out = [v['test_f1_score'] for v in results if 'test_f1_score' in v]
TA贡献1842条经验 获得超21个赞
使用列表理解来检查列表项,并获取它的每个字典'test_f1_score'
:
查看结果:
for item in results
验证当前结果以“test_f1_score”为键:
if 'test_f1_score' in item.keys()
2.1。如果它有“test_f1_score”,请将其添加到列表中:item['test_f1_score']
f1_scores = [item['test_f1_score'] for item in results if 'test_f1_score' in item.keys()]
输出:
[array([0.03381643, 0.06428571, 0.01939058, 0.02870813, 0.05673759,
0.05128205, 0.06306306, 0.01066667, 0.08275862, 0.0180791 ,
0.03755869, 0.04013378, 0.04255319, 0.07619048, 0.04494382,
0.08181818, 0.02181818, 0.02171291, 0.03367003, 0.04195804,
0.01532567, 0.05687204, 0.0591716 , 0.05825243, 0.07659574,
0.04848485, 0.01724138, 0.02247191, 0.01233046, 0.01920439]), array([0.63636364, 0.92307692, 0.96296296, 0.75 , 0.92857143,
0.83333333, 0.92307692, 0.83333333, 0.92307692, 0.92857143,
0.75 , 0.72727273, 0.8 , 0.96296296, 0.88 ,
0.88888889, 0.92307692, 0.92307692, 0.88888889, 0.88 ,
0.83333333, 0.88888889, 0.96551724, 0.88 , 0.96296296,
0.88 , 0.92307692, 0.75 , 0.83333333, 0.66666667]), array([0.00107335, 0.00068248, 0.00094757, 0.00183083, 0.00252127,
0.00114827, 0.00064725, 0.00101868, 0.00189095, 0.00243717,
0.00251467, 0.00230814, 0.00161264, 0.00114833, 0.00164609,
0.00261584, 0.00213311, 0.00060588, 0.00067877, 0.00191205,
0.00125274, 0.00163043, 0.00184945, 0.00174004, 0.00291333,
0.00147438, 0.00357782, 0.00063331, 0.00130506, 0.00108421])]
添加回答
举报