Here is the part of the code for ROC AUC Curve calculation for multiple classes.

n_classes= 5

y_test = [0,1,1,2,3,4]   #actual value
pred1 = [0,1,1,1,3,4]    #predicted value

fpr = dict()
tpr = dict()
roc_auc = dict()

for i in range(n_classes):
    fpr[i], tpr[i], _ = roc_curve(np.array(pd.get_dummies(y_test))[:, i], np.array(pd.get_dummies(pred1))[:, i])
    roc_auc[i] = auc(fpr[i], tpr[i]) 

Error :

enter image description here

I understand that there are only 4 classes are predicted 0,1,3,4 in pred1 and 5 classes 0,1,2,3,4 in the y_test. So this error arises.

How to solve this error.


1 Answer 1

df = pd.get_dummies(pred1)
add this before the for loop and instead of using pd.get_dummies(y_test) use only df

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.