gpt4 book ai didi

python - 分类报告 : labels and target_names

转载 作者:行者123 更新时间:2023-12-04 11:37:57 25 4
gpt4 key购买 nike

我有以下分类报告的输出:

             precision    recall  f1-score   support

0 0.6772 0.5214 0.5892 491
1 0.8688 0.9273 0.8971 1678

avg / total 0.8254 0.8354 0.8274 2169

数据集中的真实标签是 sp .

问题:我怎么知道哪个标签是“0”,哪个是“1”?或者:如何通过 labels= 分配标签或 target_names=以正确的顺序?

最佳答案

如无特别说明,将按字母顺序排列。所以很可能是:

0 -> 'p'

1 -> 's'

无论如何,如果您传递实际标签,它们应该按原样显示。例如:

y_true = ['p', 's', 'p', 's', 'p']
y_pred = ['p', 'p', 's', 's', 'p']

print(classification_report(y_true, y_pred))

Output:
precision recall f1-score support

p 0.67 0.67 0.67 3
s 0.50 0.50 0.50 2

avg / total 0.60 0.60 0.60 5

所以不需要做任何事情。但是,如果您更改了标签,则可以在 target_names 中传递它们。要在报告中显示的参数。

假设您已将 'p' 转换为 0,将 's' 转换为 1,那么您的代码变为:
y_true = [0, 1, 0, 1, 0]
y_pred = [0, 0, 1, 1, 0]

# Without the target_names
print(classification_report(y_true, y_pred))

0 0.67 0.67 0.67 3
1 0.50 0.50 0.50 2

avg / total 0.60 0.60 0.60 5

#With target_names
print(classification_report(y_true, y_pred, target_names=['p', 's']))

p 0.67 0.67 0.67 3
s 0.50 0.50 0.50 2

avg / total 0.60 0.60 0.60 5

关于python - 分类报告 : labels and target_names,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48493322/

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