使用pROC从现有数据中绘制ROC曲线

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

我已经创建了一个分类器,并对该模型进行了3次交叉验证,并使用几个随机种子进行了重新生成。我以0.1的间隔使用阈值,并且已经计算了每个阈值的敏感性和特异性。我从一粒种子得到的数据看起来像这样:

Index  Seed Threshold           Fold        Sn       1-Sp
1         0       0.0              1 1.0000000 1.00000000
2         0       0.0              2 1.0000000 1.00000000
3         0       0.0              3 1.0000000 1.00000000
4         0       0.1              1 1.0000000 1.00000000
5         0       0.1              2 1.0000000 1.00000000
6         0       0.1              3 1.0000000 1.00000000
7         0       0.2              1 1.0000000 1.00000000
8         0       0.2              2 1.0000000 1.00000000
9         0       0.2              3 1.0000000 1.00000000
10        0       0.3              1 1.0000000 1.00000000
11        0       0.3              2 1.0000000 1.00000000
12        0       0.3              3 1.0000000 1.00000000
13        0       0.4              1 1.0000000 0.97435897
14        0       0.4              2 1.0000000 1.00000000
15        0       0.4              3 1.0000000 1.00000000
16        0       0.5              1 0.9523810 0.89743590
17        0       0.5              2 0.9523810 1.00000000
18        0       0.5              3 1.0000000 0.89743590
19        0       0.6              1 0.9523810 0.79487180
20        0       0.6              2 0.9047619 0.67500000
21        0       0.6              3 1.0000000 0.58974359
22        0       0.7              1 0.8571429 0.56410256
23        0       0.7              2 0.8095238 0.35000000
24        0       0.7              3 0.9523810 0.17948718
25        0       0.8              1 0.8571429 0.12820513
26        0       0.8              2 0.7142857 0.20000000
27        0       0.8              3 0.8571429 0.02564103
28        0       0.9              1 0.8571429 0.10256410
29        0       0.9              2 0.6666667 0.07500000
30        0       0.9              3 0.7619048 0.02564103
31        0       1.0              1 0.8571429 0.10256410
32        0       1.0              2 0.6666667 0.05000000
33        0       1.0              3 0.7619048 0.02564103

我以为我会使用带R的pROC从数据生成ROC曲线并计算AUC。我一直在查看许多示例,但没有找到我可以要求roc过程使用已计算出的数据的示例。可能吗?

如果有人提出建议,我可以使用R或Python的其他解决方案/软件包。

r statistics cross-validation
1个回答
3
投票

老实说,我对ROC分析不是很熟悉,所以您的数据对我来说不是很清楚。但是,我们可以使用基本R图形功能复制pROC::plot.roc生成的图。您可能需要研究方法pROC:::plot.roc.roc以了解它的作用。

正在使用pROC软件包随附的示例数据。

library(pROC)
data(aSAH)
## calculate ROC
rr <- roc(aSAH$outcome, aSAH$s100b, ci=TRUE, plot=FALSE)

## plot ROC curve with package function
plot.roc(rr)

enter image description here

[要复制我们以x值1 - specificities计算的图,将x轴反转,对y轴使用灵敏度,并用x=c(-1, 0), y=c(0, 1)坐标画一条线。

with(rr, plot(-specificities, sensitivities, type="l", xaxt="n",
              xlab="", ylab="", main="My ROC curve", lwd=2,
              xlim=c(0, 1), ylim=c(0, 1)))
axis(1, axTicks(1), labels=F)
mtext(-(axTicks(1)), 1, 2, at=axTicks(1))
mtext("Specifycity", 1, 3)
mtext("Sensitivity", 2, 3)
lines(c(-1, 0), c(0, 1), col="grey")

enter image description here

看起来和我一样。

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