ROCR 包中截止值大于 1 的彩色 ROC 曲线

Colorized ROC curve with cutoff values greater than one in ROCR package

我使用 ROCR 包绘制了彩色 roc 曲线。曲线本身没有任何问题,看起来很好,但调色板显示截止点大于 1,这是不正确的,因为这些是概率,应该在 0 到 1 的范围内。我检查了我的数据集几次,但它看起来不错,我的数据集没有问题。

这是代码以及预测值及其对应的标签。here is the plotted roc curve for my classification

我最初的猜测是 ROCR 包中存在错误,但我不完全确定。任何解决问题的帮助将不胜感激。

library(ROCR)
labels <-c(1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
scores<-c(1,1,1,0.8,1,1,1,0.95,1,1,1,1,1,0,0,0,0,0,0,0.97,0,0,0,0,0,0,0,0,0,0,0,0.206,0)
pred<-prediction(scores,labels)
perf<-performance(pred,"tpr","fpr")
plot(perf,colorize=TRUE)

您似乎在 ROCR 中发现了一个错误,原因是第一个 cutoffInf,这又导致 alpha.values 的第一个条目是 Inf 还有:

> attributes(pred)$cutoffs[[1]]
[1]   Inf 1.000 0.970 0.950 0.800 0.206 0.000
> attributes(perf)$alpha.values[[1]]
[1]   Inf 1.000 0.970 0.950 0.800 0.206 0.000

到目前为止这还不是问题,但似乎 alpha.values 用于着色,这可能会导致这种奇怪的行为。将第一个条目设置为 1 而不是 Inf 解决了这个问题,这可以用作此问题的快速修复:

> attributes(perf)$alpha.values[[1]][1] <- 1
> attributes(perf)$alpha.values[[1]]
[1] 1.000 1.000 0.970 0.950 0.800 0.206 0.000
> plot(perf,colorize=TRUE)