How to fit 4 ROC curves into 1 graph?

Hi,
I was trying to fix data imbalances in R on a particular dataset and was modelling with the help of oversampling, undersampling, both, ROSE (synthetic sampling) techniques on predicted and test sets. I got 4 different ROC curves for the above 4 models separately and their respective AUC. I wanted these 4 ROC curves fit together in one graph which I could not do. Could someone please help?

Hi,
Assuming you are using ROCR package for plotting ROC curves

library(ROCR)
data(ROCR.simple)
pred <- prediction( ROCR.simple$predictions, ROCR.simple$labels )
pred2 <- prediction(abs(ROCR.simple$predictions +
rnorm(length(ROCR.simple$predictions), 0, 0.1)),
ROCR.simple$labels)
perf <- performance( pred, “tpr”, “fpr” )
perf2 <- performance(pred2, “tpr”, “fpr”)
plot(perf)
lines(perf2@x.values[[1]], perf2@y.values[[1]], col = 2)
legend(.8, .2, legend=c(“ROC1”, “ROC2”),
col=c(“black”, “red”), lty=1:2, cex=0.8)

Plotly example

library(plotly)
plot_ly(x=perf@x.values[[1]])%>%
add_lines(y=perf@y.values[[1]],name=“ROC1”) %>%
add_lines(y=perf2@y.values[[1]],name=“ROC2”)

Hope that helps

© Copyright 2013-2020 Analytics Vidhya