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?
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).
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.
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!
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))
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