scikit中roc_curve的阈值学习

时间:2016-08-25 22:47:14

标签: python python-2.7 machine-learning scikit-learn roc

我指的是以下链接和示例,并从此页面发布我感到困惑的情节图。我的困惑是,只有4个阈值,但似乎roc曲线有很多数据点(> 4个数据点),想知道roc_curve如何在底层找到更多的数据点?

http://scikit-learn.org/stable/modules/model_evaluation.html#roc-metrics

>>> import numpy as np
>>> from sklearn.metrics import roc_curve
>>> y = np.array([1, 1, 2, 2])
>>> scores = np.array([0.1, 0.4, 0.35, 0.8])
>>> fpr, tpr, thresholds = roc_curve(y, scores, pos_label=2)
>>> fpr
array([ 0. ,  0.5,  0.5,  1. ])
>>> tpr
array([ 0.5,  0.5,  1. ,  1. ])
>>> thresholds
array([ 0.8 ,  0.4 ,  0.35,  0.1 ])

enter image description here

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

正如HaohanWang所提到的,函数 roc_curve 中的参数“ drop_intermediate ”可能会降低一些次优阈值,以创建更浅的ROC曲线。 (roc_curve)。如果将参数设置为False,将显示所有阈值,例如: enter image description here 计算了所有阈值以及相应的TPR和FPR,但其中一些阈值对于绘制ROC曲线没有用。