7

我尝试了 2 种方法来绘制 ROC 曲线并获得每条 ROC 曲线的 AUC。

方法 1 - 第一种方法很简单,但我不知道如何将多条 ROC 曲线绘制在一起。我只是在使用roc.curve(hacide.test$cls, pred_rose[,2]),输出将显示 ROC 曲线并给我 AUC。

方法2 我现在可以同时绘制多条ROC曲线,但不能同时得到AUC。这是我将多条 ROC 曲线绘制在一起的方式:

library(ROCR)
pd1 <- prediction(pred_rose[,2], hacide.test$cls)
pf1 <- performance(pd1, "tpr","fpr")

pd2 <- prediction(pred_both[,2], hacide.test$cls)
pf2 <- performance(pd2, "tpr","fpr")

plot(pf1, colorize = TRUE)
plot(pf2, add = TRUE, colorize = TRUE)

这是我获得AUC的方式:

pf <- performance(pd3, "auc")
pf     # y.values is the AUC

如您所见,当我使用第二种方法时,performance()用于获取 ROC 曲线和 AUC 的方法是不同的。这里的 pf1, pf2 的输出没有 AUC 值。

方法 1 更简单,但是您知道如何使用方法 1 将 ROC 曲线绘制在一起并仍然保留每个 AUC 值吗?

4

1 回答 1

11

你可以用这个pROC包来做到这一点。print.auc在调用中使用参数plot

library(pROC)
roc_rose <- plot(roc(hacide.test$cls, pred_rose[,2]), print.auc = TRUE, col = "blue")

对于第二条 ROC 曲线,您需要更改 AUC 的 y 位置并add在同一图上使用两条曲线:

roc_rose <- plot(roc(hacide.test$cls, pred_both[,2]), print.auc = TRUE, 
                 col = "green", print.auc.y = .4, add = TRUE)
于 2016-05-16T06:49:06.463 回答