I am trying to plot ROC Curve for multiclass classification.I followed https://scikit-learn.org/stable/auto_examples/model_selection/plot_roc.html.
I used the below code to calculate y_test,and y_score
def test_epoch(net,test_loader):
y_test =[]
y_score =[]
with torch.no_grad():
for batch in test_loader:
images, labels = batch['image'], batch['grade']
images =Variable(images)
labels= Variable(labels)
outputs = net(images)
_, predicted = torch.max(outputs.data, 1)
c = (predicted == labels).squeeze().numpy()
y_score.append(outputs.numpy())
y_test.append(labels.numpy())
return y_test,y_score `
I seen that my y_test is array like below [array([0, 4, 0, 2, 1, 0, 0, 3, 0, 1, 1, 0, 3, 2, 0, 2, 2, 2, 1, 1, 1, 0,0, 0, 0, 3, 0, 0, 0, 4, 2, 1, 2, 0, 2, 1, 0, 4, 0, 0, 0, 1, 2, 2 0, 1, 2, 2, 0, 2, 0, 2, 2, 3, 2, 3, 3, 1, 1, 1, 0, 2, 0, 0, 2, 1,3, 0, 2, 0, 3, 2, 1, 0, 2, 2, 1, 0, 0, 0, 0, 2, 1, 2, 0, 3, 0, 1, 3, 0, 3, 2, 0, 3, 1, 0, 1, 2, 2, 0])]
And y_score is like[array([[ 0.30480504, -0.12213976, 0.09632117, -0.16465648, -0.44081157],[ 0.21797988, -0.09650452, 0.07616544, -0.12001953, -0.34972644],[ 0.3230184 , -0.13098559, 0.10277118, -0.17656785, -0.45888817],[ 0.38143447, -0.15880316, 0.12123139, -0.21719441, -0.5281661 ],[ 0.3427343 , -0.13945231, 0.11076729, -0.19657779, -0.4913683 ],
Whenever I called the function for plotting ROC
fpr = dict()
tpr = dict()
roc_auc = dict()
for i in range(N_classes):
fpr[i], tpr[i], _ = roc_curve(truth_val[:, i],preds_val[:, i])
roc_auc[i] = auc(fpr[i], tpr[i])
# Compute micro-average ROC curve and ROC area
fpr["micro"], tpr["micro"], _ = roc_curve(truth_val.ravel(), preds_val.ravel())
roc_auc["micro"] = auc(fpr["micro"], tpr["micro"]
I am getting this error massages,Traceback (most recent call last): File "/home/Downloads/demo 3.py", line 435, in <module> plot_roc(y_test, y_score, 5) fpr[i], tpr[i], _ = roc_curve(truth_val[:, i],preds_val[:, i]) TypeError: list indices must be integers or slices, not tuple
I could not understand how I will solve this problem.
I am highly appreciate any kind of help regarding this issue.