scikit-learn中roc_曲线的阈值

2024-06-16 08:38:39 发布

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

我指的是下面的链接和样本,并张贴了从这一页的情节图,我感到困惑。我的困惑是,只有4个阈值,但roc曲线似乎有许多数据点(>;4个数据点),想知道roc_曲线如何在底层工作以找到更多的数据点?

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


Tags: 数据import链接nparray曲线metrics样本
2条回答

正如HaohanWang所提到的,roc曲线函数中的参数'drop_intermediate'可以降低一些次优阈值,以创建更轻的roc曲线。(roc_curve)。如果将参数设置为False,则将显示所有阈值,例如: enter image description here 所有的阈值以及相应的TPRs和fpr都是计算出来的,但其中一些对于绘制ROC曲线是无用的。

相关问题 更多 >