0
$\begingroup$

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.

$\endgroup$
2
$\begingroup$
df = pd.get_dummies(pred1)
df.insert(loc=2,column='2',value=0)
#print(df)
add this before the for loop and instead of using pd.get_dummies(y_test) use only df
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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