为什么 roc_curve return 是某些 类 的阈值 (2.0) 的附加值?

Why is roc_curve return an additional value for the thresholds (2.0) for some classes?

我正在使用 python 3.5.2 和 sklearn 0.19.1

我有一个多类问题 (3 类),我正在使用 RandomForestClassifier。 对于我拥有的一个 cass 19 个独特的 predict_proba 值:

{0.0,
0.6666666666666666,
0.6736189855024448,
0.6773290780865037,
0.7150826826468751,
0.7175236925236925,
0.7775446850962057,
0.8245648135911781,
0.8631035080004867,
0.8720525244880196,
0.8739595855873906,
0.8787152225755167,
0.9289844333343654,
0.954439314892936,
0.9606503912532541,
0.9771342285323964,
0.9883370916703461,
0.9957401423931763,
1.0}

我正在计算 roc_curve 并且我期望 roc 曲线的点数与我具有唯一概率值的点数相同。这仅适用于 3 个 类!

中的 2 个

当我查看返回的阈值时,roc_curve 函数:

fpr, tpr, proba = roc_curve(....):

我看到与概率列表中的值完全相同 + 一个新值 2.0!

[2.,
1.,
0.99574014,
0.98833709,
0.97713423,
0.96065039,
0.95443931,
0.92898443,
0.87871522,
0.87395959,
0.87205252,
0.86310351,
0.82456481,
0.77754469,
0.71752369,
0.71508268,
0.67732908,
0.67361899,
0.66666667,
0. ]

为什么返回新的thresholds 2.0?我在文档中没有看到任何相关内容。

有什么想法吗?我错过了一些东西

roc_curve这样写,使得最高阈值(fpr[0]tpr[0])对应的ROC点始终为(0, 0)。如果不是这种情况,将创建一个具有任意值 max(y_score)+1 的新阈值。相关代码来自the source:

thresholds : array, shape = [n_thresholds]
    Decreasing thresholds on the decision function used to compute
    fpr and tpr. `thresholds[0]` represents no instances being predicted
    and is arbitrarily set to `max(y_score) + 1`.

if tps.size == 0 or fps[0] != 0:
    # Add an extra threshold position if necessary
    tps = np.r_[0, tps]
    fps = np.r_[0, fps]
    thresholds = np.r_[thresholds[0] + 1, thresholds]

因此,在您展示的数据中,似乎给定 1.0 分数的数据分类不正确。