我不知道在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 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]))
有一个默认为True的关键字参数
drop_intermediate
:因此,将代码更改为:
给予
你可以在documentation中找到这个
相关问题 更多 >
编程相关推荐