Roc_curve pos_label混淆

问题描述 投票:0回答:1

我有一个与

roc_curve
中的
scikit-learn
有关深度学习练习的问题,我注意到我的数据有 1 作为正标签。经过我的训练,测试准确率约为 74%,但 roc 曲线下面积 (AUC) 分数仅为 0.24。

y_pred = model.predict([x_test_real[:, 0],x_test_real[:, 1]])
fpr, tpr, thresholds = metrics.roc_curve(y_test_real, y_pred,pos_label=1)
roc_auc = metrics.auc(fpr, tpr)
print("roc_auc:  %0.2f" % roc_auc)

如果我将

pos_label
更改为0。auc分数变为0.76(显然)

y_pred = model.predict([x_test_real[:, 0],x_test_real[:, 1]])
fpr, tpr, thresholds = metrics.roc_curve(y_test_real, y_pred,pos_label=0)
roc_auc = metrics.auc(fpr, tpr)
print("roc_auc:  %0.2f" % roc_auc)

现在我进行了一个小实验,我更改了训练和测试标签(二元分类)

y_train_real = 1 - y_train_real
y_test_real = 1 - y_test_real

像这样,应该将正标签和负标签从 1 翻转到 0。然后我再次运行我的代码。这次预计大鹏 auc 的行为也会发生翻转。但不!

fpr, tpr, thresholds = metrics.roc_curve(y_test_real, y_pred,pos_label=0)

仍给出 0.80,而

pos_label=1
则给出 0.2。这让我很困惑,

  • 如果我更改训练目标中的正标签,是否不会影响 roc_curve auc 值?
  • 哪种情况的分析是正确的?
  • 输出与使用的损失函数有关系吗?我正在使用“对比损失”解决匹配和不匹配的二元分类问题。
python scikit-learn keras deep-learning roc
1个回答
0
投票

如果你能像这样发布代码和输出那就太好了 -

import numpy as np
from sklearn import metrics

y_pred = np.random.rand(100,)

y_true = np.random.randint(0,2,(100,))

fpr, tpr, thresholds = metrics.roc_curve(y_true, y_pred, pos_label=1)
print(metrics.auc(fpr, tpr))

fpr, tpr, thresholds = metrics.roc_curve(y_true, y_pred, pos_label=0)
print(metrics.auc(fpr, tpr))

y_true_new = 1 - y_true

fpr, tpr, thresholds = metrics.roc_curve(y_true_new, y_pred, pos_label=1)
print(metrics.auc(fpr, tpr))

fpr, tpr, thresholds = metrics.roc_curve(y_true_new, y_pred, pos_label=0)
print(metrics.auc(fpr, tpr))

输出-

0.5291047771979125
0.4708952228020875
0.4708952228020875
0.5291047771979125
© www.soinside.com 2019 - 2024. All rights reserved.