ROCR资料备忘:画带颜色区分的多条ROC曲线图

https://www.r-bloggers.com/a-small-introduction-to-the-rocr-package/
http://stackoverflow.com/questions/14085281/multiple-roc-curves-in-one-plot-rocr


library(ROCR)
data(ROCR.simple)
pred <- prediction( ROCR.simple$predictions, ROCR.simple$labels )
perf <- performance( pred, "tpr", "fpr" )


library(ROCR)
data(ROCR.hiv)
manypred = prediction(ROCR.hiv$hiv.nn$predictions, ROCR.hiv$hiv.nn$labels)
many.roc.perf = performance(manypred, measure ="tpr", x.measure = "fpr")
plot(many.roc.perf, col=1:10)
abline(a=0, b= 1)

final 方案:
有颜色区分的多条ROC曲线画法:

library(ROCR)
data(ROCR.simple)
preds <- cbind(p1 = ROCR.simple$predictions, p2 = abs(ROCR.simple$predictions + rnorm(length(ROCR.simple$predictions), 0, 0.1)))

pred.mat <- prediction(preds, labels = matrix(ROCR.simple$labels, 
            nrow = length(ROCR.simple$labels), ncol = 2) )

perf.mat <- performance(pred.mat, "tpr", "fpr")

library(ggplot2)
df <- data.frame(Curve=as.factor(rep(c(1,2), each=length([email protected][[1]]))), 
                 FalsePositive=c([email protected][[1]],[email protected][[2]]),
                 TruePositive=c([email protected][[1]],[email protected][[2]]))
plt <- ggplot(df, aes(x=FalsePositive, y=TruePositive, color=Curve)) + geom_line()
print(plt)

ROCR资料备忘:画带颜色区分的多条ROC曲线图_第1张图片

你可能感兴趣的:(ROCR资料备忘:画带颜色区分的多条ROC曲线图)