-2

I have trained a model based on transfer learning via Tensorflow Hub. I have been looking at many places for hints on producing Confusion matrix but I haven't been able to get to the right solution.

Does anyone know if this is possible?

The last thing I tried was to write the results in an Excel sheet but I couldn't find a formula for the multi-class computation of confusion matrix in Excel.

Any help will be great!!

colourtheweb
  • 727
  • 2
  • 13
  • 28
  • 1
    There is nothing specific to TF (or TF-Hub) regarding the computation of confusion matrices. Once you get the predictions for your data, just take any "standard" confusion matrix computation (e.g., for python [sklearn's](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html)), feed the labels and predictions to it and gt the matrix out. – GPhilo Aug 23 '19 at 12:56

1 Answers1

0

You can try tf.math.confusion_matrix function.
It computes the confusion matrix from predictions and labels.
See https://www.tensorflow.org/api_docs/python/tf/math/confusion_matrix.

Example:

my_confusion_matrix = tf.math.confusion_matrix(labels=[1, 2, 4], predictions=[2, 2, 3])
with tf.Session() as sess:
  print(sess.run(my_confusion_matrix))

# Prints #
[[0 0 0 0 0]
 [0 0 1 0 0]
 [0 0 1 0 0]
 [0 0 0 0 0]
 [0 0 0 1 0]]

# Labels are assumed to be [0, 1, 2, 3, 4] thus resulting in 5X5 confusion matrix
mlneural03
  • 833
  • 1
  • 8
  • 11