gpt4 book ai didi

python - Scikit分类报告——改变显示结果的格式

转载 作者:太空狗 更新时间:2023-10-30 00:22:19 28 4
gpt4 key购买 nike

Scikit 分类报告将仅显示两位数的精度和召回分数。是否可以让它在点后显示 4 位数字,我的意思是用 0.67 代替 0.6783?

 from sklearn.metrics import classification_report
print classification_report(testLabels, p, labels=list(set(testLabels)), target_names=['POSITIVE', 'NEGATIVE', 'NEUTRAL'])
precision recall f1-score support

POSITIVE 1.00 0.82 0.90 41887
NEGATIVE 0.65 0.86 0.74 19989
NEUTRAL 0.62 0.67 0.64 10578

此外,我是否应该担心精度得分为 1.00?谢谢!

最佳答案

我刚遇到这个老问题。classification_report确实可以有更精确的点。您只需要传入一个 digits 参数。

classification_report(y_true, y_pred, target_names=target_names, digits=4)

来自documentation :

digits : int Number of digits for formatting output floating point values

演示:

from sklearn.metrics import classification_report
y_true = [0, 1, 2, 2, 2]
y_pred = [0, 0, 2, 2, 1]
target_names = ['class 0', 'class 1', 'class 2']

print(classification_report(y_true, y_pred, target_names=target_names))

输出:

       precision    recall  f1-score   support

class 0 0.50 1.00 0.67 1
class 1 0.00 0.00 0.00 1
class 2 1.00 0.67 0.80 3

avg / total 0.70 0.60 0.61 5

4 位数字:

print(classification_report(y_true, y_pred, target_names=target_names, digits=4))

输出:

             precision    recall  f1-score   support

class 0 0.5000 1.0000 0.6667 1
class 1 0.0000 0.0000 0.0000 1
class 2 1.0000 0.6667 0.8000 3

avg / total 0.7000 0.6000 0.6133 5

关于python - Scikit分类报告——改变显示结果的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22022410/

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