Python Scikit分类报告-更改显示结果的格式
Scikit分类报告将仅用两位数显示精度和召回分数。有没有可能让它在点后显示4位数字,而不是0.67来显示0.6783Python Scikit分类报告-更改显示结果的格式,python,machine-learning,scikit-learn,classification,svm,Python,Machine Learning,Scikit Learn,Classification,Svm,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'])
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的精确分数吗?谢谢 否,使用
分类报告
无法显示更多数字。格式字符串是硬编码的,请参阅
编辑:有一个更新,请看CentAu的答案。我刚刚遇到这个老问题。 在
分类报告
中确实可以获得更高的精度点。您只需要传入一个数字
参数
classification_report(y_true, y_pred, target_names=target_names, digits=4)
从:
数字:int
用于格式化输出浮点值的位数
演示:
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
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
有4位数字:
print(classification_report(y_true, y_pred, target_names=target_names, digits=4))
输出:
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
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
谢谢你的回复。真的很有用!