I am unable to infer anything about the model from the following confusion matrix. What is the color coding actually specifying?

For example, when predicted label is 1 and true label is 1, the value in the matrix at that point is 0.20. Does that mean its accuracy? Does it mean that the model is only able to predict 1 only 20% of times when the label is actually 1?

enter image description here

PS: SO URL for a more clear image


2 Answers 2


Each element_ab shows the probability of predicting label a (horizontal axis) when the true label is b (vertical axis) For example, when the true label is 0, it will be predicted as label 2 with the probability of 0.14

The color intensity indicates the probability of each element in a row

  • $\begingroup$ Okay, so the model is not good at all? For true = pred , probabilities are close to ~0.2 $\endgroup$
    – Amanda
    Commented Apr 25, 2019 at 8:12
  • $\begingroup$ Yes, it is not good at all. Most of the data is predicted as label 1, label 2, and also label 3. $\endgroup$ Commented Apr 25, 2019 at 8:17
  • $\begingroup$ But it gives a test accuracy of 85%. What do I infer from that? $\endgroup$
    – Amanda
    Commented Apr 25, 2019 at 8:21

This is the code I use to create colors on confusion matrix.

#Create Confusion matrix

def plot_confusion_matrix(cm, classes,
                          title='Confusion matrix',
    plt.imshow(cm, interpolation='nearest', cmap=cmap)
    tick_marks = np.arange(len(classes))
    plt.xticks(tick_marks, classes, rotation=45)
    plt.yticks(tick_marks, classes)

    if normalize:
        cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
        print("Normalized confusion matrix")
        print('Confusion matrix, without normalization')

    thresh = cm.max() / 3.
    for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):
        plt.text(j, i, cm[i, j],
                 color="white" if cm[i, j] > thresh else "black")

    plt.ylabel('True label')
    plt.xlabel('Predicted label')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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