Multi Class ROC


#1

Hey, I am making a multi-class classifier with 4 classes. Now I have printed Sensitivity and Specificity along with a confusion matrix. Now I want to print the ROC plot of 4 class in the curve. As ROC is binary metric, so it is ‘given class vs rest’, but I want to add all 4 classes in the same plot.
With this code, I have got my probability -

output = model.forward(images)
p = torch.nn.functional.softmax(output, dim=1)

Can you guys please help me to get this Multi class ROC graph? Thanks.


#2

If you already have the metrics (TP, FP, TN, FN), you could probably just use scikit-learn’s methods as explained here.


#3

Well, I have done as it is saying, but in this -

```#Compute ROC curve and ROC area for each class 
fpr = dict() 
tpr = dict() 
roc_auc = dict() 
for i in range(n_classes):
 fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_score[:, i]) 
 roc_auc[i] = [auc](fpr[i], tpr[i]) 

#Compute micro-average ROC curve and ROC area 
fpr["micro"], tpr["micro"], _ = roc_curve(y_test.ravel(), y_score.ravel()) 
roc_auc["micro"] = auc(fpr["micro"], tpr["micro"])```

Do I need to change my fpr and tpr with my FP and TP in -
TP = conf_matrix.diag() and FP = conf_matrix[idx, c].sum()?

Also, I have changed n_class to nb_class = 4
How can I represent this -

for i in range(nb_classes):
    fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_score[:, i])
    roc_auc[i] = auc(fpr[i], tpr[i])

I do not have y_test, but I have dataloader_test, and what is y_score?