了解 sklearn.metrics.classification_report 参数的性质
Understanding nature of parameters of sklearn.metrics.classification_report
我遇到了以下代码:
from sklearn.metrics import classification_report
y_true = [2,1,1,1]
y_pred = [False,True,False,True]
print(classification_report(y_true, y_pred))
precision recall f1-score support
0 0.00 0.00 0.00 0
1 1.00 0.67 0.80 3
2 0.00 0.00 0.00 1
accuracy 0.50 4
macro avg 0.33 0.22 0.27 4
weighted avg 0.75 0.50 0.60 4
我无法理解 sklearn 如何在 y_true
和 y_pred
数组中执行标签之间的映射。也就是说,它如何确定 False
是否与 2
或 1
相同,与 True
相同?
我没有在 doc 中找到任何详细信息。
在 python、True=1
和 False=0
中。
所以,
y_pred = [False,True,False,True]
与
的含义相同
y_pred = [0,1,0,1]
这意味着,此代码将产生与您的代码完全相同的结果:
y_true = [2,1,1,1]
y_pred = [0,1,0,1]
print(classification_report(y_true, y_pred))
我遇到了以下代码:
from sklearn.metrics import classification_report
y_true = [2,1,1,1]
y_pred = [False,True,False,True]
print(classification_report(y_true, y_pred))
precision recall f1-score support
0 0.00 0.00 0.00 0
1 1.00 0.67 0.80 3
2 0.00 0.00 0.00 1
accuracy 0.50 4
macro avg 0.33 0.22 0.27 4
weighted avg 0.75 0.50 0.60 4
我无法理解 sklearn 如何在 y_true
和 y_pred
数组中执行标签之间的映射。也就是说,它如何确定 False
是否与 2
或 1
相同,与 True
相同?
我没有在 doc 中找到任何详细信息。
在 python、True=1
和 False=0
中。
所以,
y_pred = [False,True,False,True]
与
的含义相同y_pred = [0,1,0,1]
这意味着,此代码将产生与您的代码完全相同的结果:
y_true = [2,1,1,1]
y_pred = [0,1,0,1]
print(classification_report(y_true, y_pred))