Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to plot a confusion matrix with 90 classes?

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]]
like image 332
minks Avatar asked Oct 25 '25 00:10

minks


2 Answers

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()

enter image description here

like image 151
shiftyscales Avatar answered Oct 26 '25 15:10

shiftyscales


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))
like image 37
Alireza Zolanvari Avatar answered Oct 26 '25 15:10

Alireza Zolanvari