[英]Confusion matrix sklearn bug?
I was doing a test with sklearn.metrics.confusion_matrix
to see what happen if in the prediction array there is a class which is not in the labels and mapping arrays. 我正在使用sklearn.metrics.confusion_matrix
进行测试,以查看在预测数组中是否存在一个不在标签和映射数组中的类时发生的情况。 My code is: 我的代码是:
from sklearn.metrics import confusion_matrix as cm
a = ["positive\n", "positive\n", "negative\n", "positive\n", "negative\n"]
b = ["negative\n", "negative\n", "don't\n", "negative\n", "negative\n"]
m = ["positive\n", "negative\n"]
c = cm(a, b, m)
TN, FP, FN, TP = c.ravel()
print(c)
print("")
print("{} {} {} {}\n".format(TN, FP, FN, TP))
The ouput is: 输出是:
[[0 3]
[0 1]]
0 3 0 1
So the class don't
is skipped. 因此, don't
跳过该类。
But if you look at the documentation for the version v0.21.2
which is the one I installed the ravel()
method "should" output the values of the confusion matrix as I wrote: TN, FP, FN, TP. 但是,如果您查看版本v0.21.2
的文档 ,那是我安装的ravel()
方法的文档 ,“应该”输出我所写的混淆矩阵的值:TN,FP,FN,TP。 The output of my print
is different. 我的print
输出是不同的。 It seems that the real ouput of ravel()
is flipped: TP, FN, FP, TN. 似乎ravel()
的实际输出被翻转了:TP,FN,FP,TN。 Is my thought right? 我的想法对吗?
There is no bug. 没有错误。 You have defined labels: 您已定义标签:
m = ["positive\n", "negative\n"]
therefore "positive\\n"
is negative and "negative\\n"
is positive. 因此, "positive\\n"
为负, "negative\\n"
为正。 And the result meets your specification. 结果符合您的要求。
If you modify m
this way: 如果以这种方式修改m
:
m = ["negative\n", "positive\n"]
you will get: 你会得到:
1 0 3 0
for TN, FP, FN, TP
, respectively. 分别用于TN, FP, FN, TP
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.