0

I have 6 classes and I used tf-slim in Tensorflow to obtained the confusion matrix such as

[[41  2  0  0  0  0]
 [ 1 11  4  1  0  0]
 [ 0  1  12  0  0  0]
 [ 0  0  0 22  1  0]
 [ 0  0  0  0  7  0]
 [ 0  0  0  0  0 20]]

My question is that what is confusion matrix order of the above table? Is it right if I said that the columns represent the prediction label, while the rows represent the true label? Some reference said on opposite side.

Jame
  • 3,746
  • 6
  • 52
  • 101

2 Answers2

2

Did you use tf.confusion_matrix(labels,predictions)?

If so, the columns represent the predicton labels, whereas the rows represent the real labels.

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
M. Rath
  • 71
  • 4
  • Thanks. So for example of class 1 (index from 0 to n-1). It correctly predict 11 and false to class is 1 +4 + 1=6. Am I right? – Jame Jan 26 '18 at 08:52
  • For class1, you have 11 true positives, 3 false positives (i.e. you predicted class 1 which is not true) and 6 false negatives (i.e. you didn't predict class 1, although that would've been correct). – M. Rath Jan 26 '18 at 09:41
1

The usual representation is

    PREDICTED
 [[41  2  0  0  0  0]
T [ 1 11  4  1  0  0]
R [ 0  1  12 0  0  0]
U [ 0  0  0 22  1  0]
E [ 0  0  0  0  7  0]
  [ 0  0  0  0  0 20]]

As pointed out by M. Rath (+1), this is also what Tensorflow does. This means for 41 samples you correctly predicted class 0. For 2 samples, you predicted class 1, but it actually was class 0.

Please note that you can also manipulate the order for visualizations. So instead of

class 0, class 1, class 2

you could have (for both, prediction and true value) the order

class 0, class 2, class 1

This contains the same information, but a visualization might convey a different story. See my masters thesis Analysis and Optimization of Convolutional Neural Network Architectures page 48 (Confusion Matrix Ordering), especially figure 5.12 and 5.13.

An implementation can be found in the tool clana

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958