fastai confusion matrix classes not in order

Viewed 771

I am using fastai to plot a confusion matrix of my fastai model. I am using this code:

interp = ClassificationInterpretation.from_learner(learn)
interp.plot_confusion_matrix()

My classes are [0,1,2,3,4,5,6,7,8,9,10,11,12,13].

The confusion matrix prints the classes out of order, as such: [0,1,10,11,12,13,4,5,6,7,8,9]

How do I fix this?

1 Answers

One simple alternative is to change your categories by adding leading zeroes for the classes (and not using the numbers):

  • 1 => 01
  • 2 => 02
  • ...
  • 10 => 10

You could use the format 02d like this:

"{:02d}".format(category) or even better (Python 3.x): `f"{category:02d}".

That way, you are sure that 02 is before 10.

Related