2

I am encountering this error when trying to use the confusion matrix in my binary classification problem. Y and Yhat are both numpy arrays. I have tried the .argmax as the proposed solution - I don't get the error anymore but the output is not the confusion matrix that I know.

Accuracy: 0.9982449999999999
Accuracy: 0.9983374013937532

shape of y =  (1, 200000)
shape of yhat =  (1, 200000)

The error

 ValueError                                Traceback (most recent call last) <ipython-input-13-ebb660b4585a> in <module>()
     12 print("shape of yhat = ", yhat.shape)
     13 
---> 14 cm = confusion_matrix(y,yhat)
     15 
     16 print("confusion matrix = ", cm)

/anaconda3/lib/python3.6/site-packages/sklearn/metrics/classification.py in confusion_matrix(y_true, y_pred, labels, sample_weight)
    250     y_type, y_true, y_pred = _check_targets(y_true, y_pred)
    251     if y_type not in ("binary", "multiclass"):
--> 252         raise ValueError("%s is not supported" % y_type)
    253 
    254     if labels is None:

ValueError: multilabel-indicator is not supported
Alexander McFarlane
  • 10,643
  • 9
  • 59
  • 100
Subhash Desai
  • 21
  • 1
  • 2
  • 2
    Hi! Welcome to StackOverflow! I think you could greatly improve your post if you had proper formatting on it. Also, you should consider providing a [Minimal Complete Verifiable Example (MCVE)](https://stackoverflow.com/help/mcve) – norok2 Sep 07 '18 at 12:30
  • Hi, thanks. you can tell I'm new to stack overflow as well as NN & Python. the code is very simple and it is outlined in the error msg: cm = confusion_matrix(y,yhat). I tested it on two cooked up arrays and it worked. However, not working for my real problem. – Subhash Desai Sep 07 '18 at 12:41
  • @SubhashDesai Welcome to Stackoverflow, in future you should include the code as well – epistemophiliac Oct 30 '18 at 20:34

1 Answers1

1

Append your code as follows

cm = confusion_matrix(y.argmax(axis=1),yhat.argmax(axis=1))

Asked here before

epistemophiliac
  • 829
  • 8
  • 20