1

I am doing a face recog model and I am testing it. It works. The only problem is during documentation the numbers inside of the simple 2x2 confusion matrix are off and are not centered. Which doesnt make sense since I thought I am alighing them according to the cell they are in.

Here is the funcion I am using to create the confusion matrix and the output:

def plot_confusion_matrix(c_matrix):
    norm_conf = []
    for i in c_matrix:
        a = 0
        tmp_arr = []
        a = sum(i, 0)
        for j in i:
            tmp_arr.append(float(j)/float(a))
        norm_conf.append(tmp_arr)

    fig = plt.figure()
    ax = fig.add_subplot(111)
    res = ax.imshow(np.array(norm_conf), cmap=plt.cm.Greys, interpolation='nearest')

    width = len(c_matrix)
    height = len(c_matrix[0])

    for x in range(width):
        for y in range(height):
            ax.annotate(str(c_matrix[x][y]), xy=(y, x), 
                        horizontalalignment='center',
                        verticalalignment='center', color = 'green', size = 20)

    fig.colorbar(res)
    numbers = '01'
    plt.xticks(range(width), numbers[:width])
    plt.yticks(range(height), numbers[:height])

    plt.show()

enter image description here

Gabriel
  • 40,504
  • 73
  • 230
  • 404

0 Answers0