Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plot.roc for multiclass.roc in pROC package?

Tags:

r

roc

auc

I am trying to plot multiclass ROC curves but I have not found anything fruitful in the pROC package. Here's some start code:

data(iris)
library(randomForest)
library(pROC)
set.seed(1000)
# 3-class in response variable
rf = randomForest(Species~., data = iris, ntree = 100)
# predict(.., type = 'prob') returns a probability matrix
predictions <- as.numeric(predict(rf, iris, type = 'response'))
roc.multi <- multiclass.roc(iris$Species, predictions)
auc(roc.multi)

How do I plot the ROC curves for individual classes?

like image 958
AngryPanda Avatar asked Dec 09 '15 02:12

AngryPanda


People also ask

How do you plot a multiclass ROC curve?

In order to extend ROC curve and ROC area to multi-label classification, it is necessary to binarize the output. One ROC curve can be drawn per label, but one can also draw a ROC curve by considering each element of the label indicator matrix as a binary prediction (micro-averaging).

Can we use AUC ROC curve for multi class model?

Like I said before, the AUC-ROC curve is only for binary classification problems. But we can extend it to multiclass classification problems by using the One vs All technique.

How do you plot a ROC graph?

To plot the ROC curve, we need to calculate the TPR and FPR for many different thresholds (This step is included in all relevant libraries as scikit-learn ). For each threshold, we plot the FPR value in the x-axis and the TPR value in the y-axis. We then join the dots with a line. That's it!


1 Answers

Check the names of the roc.multi, you should found a name called rocs, which stores individual roc curve info for each classes.

So you can use plot.roc and lines.roc to visualize all of them:

rs <- roc.multi[['rocs']]
plot.roc(rs[[1]])
sapply(2:length(rs),function(i) lines.roc(rs[[i]],col=i))
like image 65
Zhang Cheng Avatar answered Sep 25 '22 14:09

Zhang Cheng