Python 计算AUC曲线时如何创建阈值?
我对python中的Python 计算AUC曲线时如何创建阈值?,python,scikit-learn,Python,Scikit Learn,我对python中的scikit learn中如何生成阈值感到困惑。对于下面的示例,生成了四个阈值,其中当我将pred中的第三个值更改为0.6时,阈值的数量降至3。有人能解释为什么会这样吗 #Example 1 import numpy as np from sklearn import metrics y = np.array([0, 0, 1, 1]) pred = np.array([0.1, 0.4, 0.3, 0.8]) #Please note the thord value he
scikit learn
中如何生成阈值感到困惑。对于下面的示例,生成了四个阈值,其中当我将pred
中的第三个值更改为0.6
时,阈值的数量降至3。有人能解释为什么会这样吗
#Example 1
import numpy as np
from sklearn import metrics
y = np.array([0, 0, 1, 1])
pred = np.array([0.1, 0.4, 0.3, 0.8]) #Please note the thord value here is `0.3`
fpr, tpr, thresholds = metrics.roc_curve(y, pred, pos_label=1)
fpr, tpr, thresholds
(array([0. , 0.5, 0.5, 1. ]),
array([0.5, 0.5, 1. , 1. ]),
array([0.8, 0.4, 0.3, 0.1]))
#Example 2
y = np.array([0, 0, 1, 1])
pred = np.array([0.1, 0.4, 0.6, 0.8])
fpr, tpr, thresholds = metrics.roc_curve(y, pred, pos_label=1)
fpr, tpr, thresholds
(array([0., 0., 1.]),
array([0.5, 1. , 1. ]),
array([0.8, 0.6, 0.1]))
有一个关键字参数
drop\u intermediate
,默认为True:
drop_中间值:布尔值,可选(默认值为True)
是否降低一些在绘制的ROC曲线上不会出现的次优阈值。这对于创建较轻的ROC曲线非常有用。
版本0.17中新增:参数drop_intermediate
因此,将代码更改为:
fpr, tpr, thresholds = metrics.roc_curve(y, pred, pos_label=1, drop_intermediate=False)
fpr, tpr, thresholds
给予
你可以在
(array([0. , 0. , 0.5, 1. ]),
array([0.5, 1. , 1. , 1. ]),
array([0.8, 0.6, 0.4, 0.1]))