I wish to plot the confusion matrix for my classification model. It has about 20000 documents that need to be classified to 90 classes. The confusion matrix I receive is huge. I wish to plot this but I only seem to find binary classification plots everywhere. Is it possible to plot this multi-class confusion matrix? I tried some methods but it does't display a clear one.
This is how my confusion matrix looks like:
[[3919 344 0 ..., 0 0 1]
[ 267 2739 0 ..., 0 0 0]
[ 1 6 17 ..., 0 0 0]
...,
[ 4 1 0 ..., 6 0 0]
[ 0 2 0 ..., 0 0 0]
[ 6 1 0 ..., 0 0 15]]
Here is some sample code using matplotlib (EDIT: added grid and switching off the interpolation)
import numpy as np
import matplotlib.pyplot as plt
confmat=np.random.rand(90,90)
ticks=np.linspace(0, 89,num=90)
plt.imshow(confmat, interpolation='none')
plt.colorbar()
plt.xticks(ticks,fontsize=6)
plt.yticks(ticks,fontsize=6)
plt.grid(True)
plt.show()

Disclaimer,
Hi,
I think plotting a confusion matrix is not a good solution. I suggest you to save it as a html or csv file.
PyCM is a python module which can help you to show a multi-class confusion matrix through different types of reports such as a html report.
There is a simple code for saving a html report of a confusion matrix.
cm.save_html("file_name",color=(R,G,B))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With