R: Plot multiple different coloured ROC curves using ROCR

its*_*lwg 4 plot r machine-learning data-mining roc

The following code was taken from @adibender answer to "Multiple ROC curves in one plot ROCR". The code is partly from ?plot.performance.

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")
plot(perf.mat)
Run Code Online (Sandbox Code Playgroud)

I want to illustrate several ROC curves in a single plot, like the code above, using the r package ROCR. However, i would want the ROC curves to be in different colours. How do i apply different colours to different curves? Thanks, in advance.

San*_*Dey 8

试试这个(你可以用它来做ROCR):

library(ROCR)
data(ROCR.simple)
preds <- cbind(p1 = ROCR.simple$predictions, 
               p2 = abs(ROCR.simple$predictions + 
                          rnorm(length(ROCR.simple$predictions), 0, 0.1)))
n <- 2 # you have n models
colors <- c('red', 'blue') # 2 colors
for (i in 1:n) {
   plot(performance(prediction(preds[,i],ROCR.simple$labels),"tpr","fpr"), 
                                           add=(i!=1),col=colors[i],lwd=2)
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明