Question

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.

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with datascience.stackexchange
scroll top