加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – Scikit Learn算法有不正确的预测,但ROC曲线是完美的?

发布时间:2020-12-20 13:49:07 所属栏目:Python 来源:网络整理
导读:这是我第一次使用scikit学习指标,我想用这个库绘制一条roc曲线. 该ROC曲线表示AUC = 1.00,我知道这是不正确的.这是代码: from sklearn.metrics import roc_curve,aucimport pylab as pldef show_roc(test_target,predicted_probs):# set number 1actual = [
这是我第一次使用scikit学习指标,我想用这个库绘制一条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]
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.213,0.182]

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

# Plot ROC curve
pl.clf()
pl.plot(fpr,label='ROC curve (area = %0.2f)' % roc_auc)
pl.plot([0,1],[0,'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,0]
prediction_probas = [0.9,0.9,0.1,0.1]

fpr,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学习文档,我很难过.

解决方法

你得到了一个完美的曲线,因为你的标签也实际上与你的预测分数(即prediction_probas)对齐.即使TP得分较低,1s和-1s之间仍然存在可区分的边界,这转化为它们的分类可接受的阈值.

尝试将较高得分1中的一个更改为-1,或将-1中的任何一个更改为1并查看生成的曲线

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读