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

问题描述 投票:1回答:1

我使用的是python 3.5.2和sklearn 0.19.1

我有一个muticlass问题(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. ]

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

任何的想法 ?我错过了什么

python scikit-learn probability roc
1个回答
2
投票

编写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得分错误的数据。

© www.soinside.com 2019 - 2024. All rights reserved.