scikit中混淆矩阵的正确命名

Right naming of confusion matrix in scikit

假设我有以下测试值:

y_test2 = [0, 0, 1, 1]

以及以下预测值:

y_pred2 = [1, 0, 1, 1]

所以我有一个二进制分类问题 {0,1} 为 类。 如果我使用 sklearn confusion_matrix:

confusion_matrix(y_test2, y_pred2)
array([[1, 1], #one 0 was predicted as 0 (TruePositive),  one 0 was predicted as 1 (FalseNegative)
       [0, 2]], dtype=int64) #two 1 were predicted as 1 (TrueNegatives)

所以对我来说是:

TP: 1
FN: 1
TN: 2
FP: 0

不过,当我运行用ravelconfusion_matrix时,跟着scikit学习文档:

tn, fp, fn, tp = confusion_matrix(y_test2, y_pred2).ravel()
(1, 1, 0, 2)

为什么 scikit 将 1 解释为真值?为什么文档中没有提到它:https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html 使用命名约定进行二进制分类还有其他问题吗?有没有机会避免这种情况?

documentation中的描述:

Thus in binary classification, the count of true negatives is C(0,0) , false negatives is C(1,0), true positives is C(1,1) and false positives is C(0,1) .

所以从你的阵列

array([[1, 1], 
       [0, 2]], dtype=int64)

TN: 1
FN: 0
TP: 2
FP: 1