【问题标题】:Scikit Learn Algorithm has incorrect predictions but ROC curve is perfect?Scikit Learn Algorithm 预测不正确但 ROC 曲线完美?
【发布时间】:2015-07-06 15:26:26
【问题描述】:

这是我第一次使用 scikit learn metrics,我想使用这个库绘制 roc 曲线。

这条 ROC 曲线表明 AUC=1.00,我知道这是不正确的。代码如下:

from sklearn.metrics import roc_curve, auc
import pylab as pl

def show_roc(test_target, predicted_probs):

# set number 1

actual = [1, -1, -1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1]
prediction_probas = [0.374,  0.145,  0.263,  0.129,  0.215,  0.538, 0.24, 0.183, 0.402, 0.2, 0.281,
                0.277, 0.222, 0.204, 0.193, 0.171, 0.401, 0.204, 0.213, 0.182]

fpr, tpr, thresholds = roc_curve(actual, prediction_probas)
roc_auc = auc(fpr, tpr)

# Plot ROC curve
pl.clf()
pl.plot(fpr, tpr, label='ROC curve (area = %0.2f)' % roc_auc)
pl.plot([0, 1], [0, 1], 'k--')
pl.xlim([-0.1, 1.2])
pl.ylim([-0.1, 1.2])
pl.xlabel('False Positive Rate')
pl.ylabel('True Positive Rate')
pl.title('Receiver operating characteristic example')
pl.legend(loc="lower right")
pl.show()

对于这第一组,这是图表: http://i.stack.imgur.com/pa93c.png

概率非常低,尤其是正面,我不知道为什么它会为这些输入显示完美的 ROC 图。

# set number 2

actual = [1,1,1,0,0,0]
prediction_probas = [0.9,0.9,0.1,0.1,0.1,0.1]

fpr, tpr, thresholds = roc_curve(actual, prediction_probas)
roc_auc = auc(fpr, tpr)

# Plot ROC curve
pl.clf()
pl.plot(fpr, tpr, label='ROC curve (area = %0.2f)' % roc_auc)
pl.plot([0, 1], [0, 1], 'k--')
pl.xlim([-0.1, 1.2])
pl.ylim([-0.1, 1.2])
pl.xlabel('False Positive Rate')
pl.ylabel('True Positive Rate')
pl.title('Receiver operating characteristic example')
pl.legend(loc="lower right")
pl.show()

这里的第二组是图形输出:

这个好像比较合理,我把它加进去比较一下。

我几乎一整天都在阅读 scikit learn 文档,但我很难过。

【问题讨论】:

    标签: python scikit-learn roc


    【解决方案1】:

    你得到了一条完美的曲线,因为你的标签又名actual 与你的预测分数一致,即prediction_probas。尽管 TP 分数很低,但 1 和 -1 之间仍然存在可区分的边界,这意味着它们处于分类可接受的阈值中。

    尝试将得分较高的 1 之一更改为 -1,或将任何 -1 更改为 1,然后查看结果曲线

    【讨论】:

      猜你喜欢
      • 2017-06-04
      • 2016-09-09
      • 2013-10-08
      • 2019-04-19
      • 2016-06-11
      • 2016-08-24
      • 2018-05-14
      • 2018-07-30
      • 2021-03-31
      相关资源
      最近更新 更多