I have tried 2 methods to plot ROC curve and get AUC for each ROC curve.
Method 1
- The first method is simple but I don't know how to plot multiple ROC curves together.
I am simply using roc.curve(hacide.test$cls, pred_rose[,2])
, the output will show the ROC curve and gives me the AUC.
Method 2 I can plot multiple ROC curves together now, but cannot get AUC at the same time. This is the way I plot multiple ROC curves together:
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)
This is the way I get AUC:
pf <- performance(pd3, "auc")
pf # y.values is the AUC
As you can see, when I am using this second method, the performance()
method used for getting ROC curve and AUC is different. The output of pf1, pf2 here has no AUC values.
Method 1 is simpler, but do you know how can I use method 1 to plot ROC curves together and still keep each AUC values?
You can use the add = TRUE argument the plot function to plot multiple ROC curves. library (pROC) a=rbinom (100, 1, 0.25) b=runif (100) c=rnorm (100) fit1=glm (a~b+c, family='binomial') fit2=glm (a~c, family='binomial') Predict on the same data you trained the model with (or hold some out to test on if you want)
You can get the AUC of the ROC curve by roc1$auc, and can add it either using the text () function in base R plotting, or perhaps just toss it in the legend. I don't know how to quantify confidence intervals...or if that is even a thing you can do with ROC curves. Someone else will have to fill in the details on that one. Sorry.
So if we use plot_roc_curve two times without the specifying ax parameter it will plot two graphs. So here we store the first gragh in the figure variable and access its axis and provide to the next plot_roc_curve function, so that the plot appear of the axes of the first graph only.
Basically plot_roc_curve function plot the roc_curve for the classifier. So if we use plot_roc_curve two times without the specifying ax parameter it will plot two graphs.
You can do this with the pROC
package. Use the print.auc
argument in the call to plot
:
library(pROC)
roc_rose <- plot(roc(hacide.test$cls, pred_rose[,2]), print.auc = TRUE, col = "blue")
And for the second ROC curve you need to change the y position of the AUC and use add
the plot the two curves on the same plot:
roc_rose <- plot(roc(hacide.test$cls, pred_both[,2]), print.auc = TRUE,
col = "green", print.auc.y = .4, add = TRUE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With