Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multilabel-indicator is not supported for confusion matrix

multilabel-indicator is not supported is the error message I get, when trying to run:

confusion_matrix(y_test, predictions)

y_test is a DataFrame which is of shape:

Horse | Dog | Cat 1       0     0 0       1     0 0       1     0 ...     ...   ... 

predictions is a numpy array:

[[1, 0, 0],  [0, 1, 0],  [0, 1, 0]] 

I've searched a bit for the error message, but haven't really found something I could apply. Any hints?

like image 813
Khaine775 Avatar asked Oct 26 '17 12:10

Khaine775


People also ask

What is Multilabel confusion matrix?

The multilabel_confusion_matrix calculates class-wise or sample-wise multilabel confusion matrices, and in multiclass tasks, labels are binarized under a one-vs-rest way; while confusion_matrix calculates one confusion matrix for confusion between every two classes.

How do you plot the confusion matrix in Seaborn?

Plotting Confusion Matrix Using Seaborn To plot a confusion matrix, we have to create a data frame of the confusion matrix, and then we can use the heatmap() function of Seaborn to plot the confusion matrix in Python. For example, let's create a random confusion matrix and plot it using the heatmap() function.


2 Answers

No, your input to confusion_matrix must be a list of predictions, not OHEs (one hot encodings). Call argmax on your y_test and y_pred, and you should get what you expect.

confusion_matrix(     y_test.values.argmax(axis=1), predictions.argmax(axis=1))  array([[1, 0],        [0, 2]]) 
like image 77
cs95 Avatar answered Sep 22 '22 19:09

cs95


The confusion matrix takes a vector of labels (not the one-hot encoding). You should run

confusion_matrix(y_test.values.argmax(axis=1), predictions.argmax(axis=1)) 
like image 33
Joshua Howard Avatar answered Sep 23 '22 19:09

Joshua Howard