我尝试了 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 值吗?