I am using a confusion matrix to measure the performance of my classifier. This example would work fine for me (its from here), but I get the whole time TypeError: Invalid dimensions for image data
from numpy import * import matplotlib.pyplot as plt from pylab import * conf_arr = [[50.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [3.0, 26.0, 0.0, 0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0], [4.0, 1.0, 0.0, 5.0, 0.0, 0.0, 0.0], [3.0, 0.0, 1.0, 0.0, 6.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 47.0, 0.0], [2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 8.0]] norm_conf = [] for i in conf_arr: a = 0 tmp_arr = [] a = sum(i,0) for j in i: tmp_arr.append(float(j)/float(a)) norm_conf.append(tmp_arr) plt.clf() fig = plt.figure() ax = fig.add_subplot(111) res = ax.imshow(array(norm_conf), cmap=cm.jet, interpolation='nearest') cb = fig.colorbar(res) savefig("confmat.png", format="png") I am new to python and matplotlib. Any help?
Matplot version is 1.1.1. and here is the full traceback:
after res =... I get
TypeError Traceback (most recent call last) C:\Python27\lib\site-packages\SimpleCV\Shell\Shell.pyc in <module>() ----> 1 res = ax.imshow(array(norm_conf), cmap=cm.jet, interpolation='nearest') C:\Python27\lib\site-packages\matplotlib\axes.pyc in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filter rad, imlim, resample, url, **kwargs) 6794 filterrad=filterrad, resample=resample, **kwargs) 6795 -> 6796 im.set_data(X) 6797 im.set_alpha(alpha) 6798 self._set_artist_props(im) C:\Python27\lib\site-packages\matplotlib\image.pyc in set_data(self, A) 409 if (self._A.ndim not in (2, 3) or 410 (self._A.ndim == 3 and self._A.shape[-1] not in (3, 4))): --> 411 raise TypeError("Invalid dimensions for image data") 412 413 self._imcache =None TypeError: Invalid dimensions for image data SimpleCV:105> cb = fig.colorbar(res) For print norm_conf I get now results: [[1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],...]]. I corrected the indentation problem. But my confusion .png is pretty distorted. Further how should I proceed to label the squares in the matrix?