sciki中混淆矩阵的正确命名

2024-10-01 22:29:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下测试值:

y_test2 = [0, 0, 1, 1]

以及以下预测值:

y_pred2 = [1, 0, 1, 1]

所以我有一个以{0,1}为类的二进制分类问题。 如果我使用sklearnconfusion_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

但是,当我用ravel运行confusion\u矩阵时,我学习了以下文档:

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 对于使用命名约定的二进制分类,我还可能面临其他问题吗?有机会避免吗


Tags: 文档as二进制分类scikitonematrixtest2
1条回答
网友
1楼 · 发布于 2024-10-01 22:29:36

请看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

相关问题 更多 >

    热门问题