我正在使用python 3.5.2和sklearn 0.19.1
我有一个muticlass问题(3个班),我正在使用RandomForestClassifier
。
对于我的一个凯斯
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?我在文档中没有看到与此相关的任何内容。
有什么主意吗?我想念什么
答案 0 :(得分: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
被错误分类的情况下。