Confusion Matrix with number of classified/misclassified instances on it (Python/Matplotlib)

前端 未结 2 1691
离开以前
离开以前 2020-12-09 21:02

I am plotting a confusion matrix with matplotlib with the following code:

from numpy import *
import matplotlib.pyplot as plt
from pylab import *

conf_arr =         


        
相关标签:
2条回答
  • 2020-12-09 21:15

    You can use text to put arbitrary text in your plot. For example, inserting the following lines into your code will write the numbers (note the first and last lines are from your code to show you where to insert my lines):

    res = ax.imshow(array(norm_conf), cmap=cm.jet, interpolation='nearest')
    for i, cas in enumerate(conf_arr):
        for j, c in enumerate(cas):
            if c>0:
                plt.text(j-.2, i+.2, c, fontsize=14)
    cb = fig.colorbar(res)
    

    0 讨论(0)
  • 2020-12-09 21:22

    The only way I could really see of doing it was to use annotations. Try these lines:

    for i,j in ((x,y) for x in xrange(len(conf_arr))
                for y in xrange(len(conf_arr[0]))):
        ax.annotate(str(conf_arr[i][j]),xy=(i,j))
    

    before saving the figure. It adds the numbers, but I'll let you figure out how to get the sizes of the numbers how you want them.

    0 讨论(0)
提交回复
热议问题