roc_curve#

sklearn.metrics.roc_curve(y_true, y_score, *, pos_label=None, sample_weight=None, drop_intermediate=True)[源代码]#

计算受试者工作特征(ROC)。

注意:此实现仅限于二进制分类任务。

阅读更多的 User Guide .

参数:
y_true形状类似阵列(n_samples,)

真正的二进制标签。如果标签不是{-1,1}或{0,1},则应显式给出pos_Label。

y_score形状类似阵列(n_samples,)

目标分数可以是正类别的概率估计、置信值或决策的非阈值测量(如某些分类器上的“decision_function”返回的)。为 decision_function 分数、大于或等于零的值应表示阳性类别。

pos_labelint、float、bool或string,默认值为无

The label of the positive class. When pos_label=None, if y_true is in {-1, 1} or {0, 1}, pos_label is set to 1, otherwise an error will be raised.

sample_weight形状类似数组(n_samples,),默认=无

样本重量。

drop_intermediate布尔,默认=True

是否降低一些不会出现在绘制的ROC曲线上的次优阈值。这对于创建更亮的ROC曲线很有用。

Added in version 0.17: 参数 drop_intermediate .

返回:
fpr形状的nd数组(>2,)

增加假阳性率,使元素i是评分>=的预测假阳性率 thresholds[i] .

tpr形状的nd数组(>2,)

提高真阳性率, i 是评分>=的预测真阳性率 thresholds[i] .

thresholds形状的nd数组(n_thields,)

降低用于计算fpr和tpr的决策函数的阈值。 thresholds[0] 表示没有预测任何实例,并被任意设置为 np.inf .

参见

RocCurveDisplay.from_estimator

绘制给定估计量和一些数据的受试者工作特征(ROC)曲线。

RocCurveDisplay.from_predictions

在给定真实值和预测值的情况下绘制接收器工作特征(ROC)曲线。

det_curve

计算不同概率阈值的错误率。

roc_auc_score

计算ROC曲线下面积。

注意到

由于阈值是从低到高的值排序的,因此在返回阈值时会颠倒它们,以确保它们与两者相对应 fprtpr ,它们在计算过程中按相反顺序排序。

An arbitrary threshold is added for the case tpr=0 and fpr=0 to ensure that the curve starts at (0, 0). This threshold corresponds to the np.inf.

引用

[1]

Wikipedia entry for the Receiver operating characteristic <https://en.wikipedia.org/wiki/Receiver_operating_characteristic> _

[2]

福塞特T ROC分析简介 [J] .模式识别信件,2006,27(8):861-874。

示例

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