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

来源:互联网 发布:天书世界神将熔炼数据 编辑:程序博客网 时间:2024/05/04 16:50

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(perf.mat@x.values[[1]]))),                  FalsePositive=c(perf.mat@x.values[[1]],perf.mat@x.values[[2]]),                 TruePositive=c(perf.mat@y.values[[1]],perf.mat@y.values[[2]]))plt <- ggplot(df, aes(x=FalsePositive, y=TruePositive, color=Curve)) + geom_line()print(plt)

这里写图片描述

1 0
原创粉丝点击