title: confusion matrix error "Classification metrics can't handle a mix of multilabel-indicator and multiclass targets"
body: <p>I am getting a</p>
  
  <pre><code>Classification metrics can't handle a mix of multilabel-indicator and multiclass targets
  </code></pre>
  
  <p>error when I try to use confusion matrix.</p>
  
  <p>I am doing my first deep learning project. I am new to it. I am using the mnist dataset provided by keras. I have trained and tested my model successfully. </p>
  
  <p>However, when I try to use the scikit learn confusion matrix I get the error stated above. I have searched for an answer and while there are answers on this error, none of them worked for me. From what I found online it probably has something to do with the loss function (I use the <code>categorical_crossentropy</code> in my code). I tried changing it to <code>sparse_categorical_crossentropy</code> but that just gave me the </p>
  
  <pre><code>Error when checking target: expected dense_2 to have shape (1,) but got array with shape (10,)
  </code></pre>
  
  <p>when I run the <code>fit()</code> function on the model. </p>
  
  <p>This is the code. (I have left out the imports for the sake of brevity)</p>
  
  <pre><code>model = Sequential()
  model.add(Dense(512, activation='relu', input_shape=(28 * 28,)))
  model.add(Dense(10, activation='softmax')) 
  
  model.compile(optimizer='Adam', loss='categorical_crossentropy', metrics=['accuracy'])
  
  (train_images, train_labels), (test_images, test_labels) = mnist.load_data()
  
  train_images = train_images.reshape((60000, 28 * 28))
  train_images = train_images.astype('float32') / 255
  
  test_images = test_images.reshape((10000, 28 * 28))
  test_images = test_images.astype('float32') / 255
  
  train_labels = to_categorical(train_labels)
  test_labels = to_categorical(test_labels)
  
  model.fit(train_images, train_labels, epochs=10, batch_size=128)
  
  rounded_predictions = model.predict_classes(test_images, batch_size=128, verbose=0)
  
  cm = confusion_matrix(test_labels, rounded_predictions)
  </code></pre>
  
  <p>How can i fix this? </p>