-2

I want to plot my values to be something like this:

enter image description here

I have 4x12 values in a list.

values = [[2.78, 2.78, 2.78, 2.79, 2.79, 2.79, 2.8, 2.8, 2.81, 2.82, 2.82, 2.77], 
          [2.98, 2.98, 2.98, 2.99, 2.99, 2.99, 3.0, 3.0, 3.01, 3.02, 3.03, 2.98], 
          [3.01, 3.01, 3.01, 3.01, 3.01, 3.02, 3.02, 3.03, 3.04, 3.04, 3.05, 3.01], 
          [2.98, 2.98, 2.98, 2.99, 2.99, 2.99, 3.0, 3.01, 3.01, 3.02, 3.03, 2.99]]

I've tried to follow the confusion matrix method but it seems limited only for an equal array shape Confusion Matrix with number of classified/misclassified instances on it (Python/Matplotlib)

any advice?

Community
  • 1
  • 1
Gerry Julian
  • 43
  • 2
  • 7

1 Answers1

1

Just copy the code of the question that you put: Confusion Matrix with number of classified/misclassified instances on it (Python/Matplotlib):

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

conf_arr = [[2.78, 2.78, 2.78, 2.79, 2.79, 2.79, 2.8, 2.8, 2.81, 2.82, 2.82, 2.77], 
          [2.98, 2.98, 2.98, 2.99, 2.99, 2.99, 3.0, 3.0, 3.01, 3.02, 3.03, 2.98], 
          [3.01, 3.01, 3.01, 3.01, 3.01, 3.02, 3.02, 3.03, 3.04, 3.04, 3.05, 3.01], 
          [2.98, 2.98, 2.98, 2.99, 2.99, 2.99, 3.0, 3.01, 3.01, 3.02, 3.03, 2.99]]

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(figsize=(14, 5))
ax = fig.add_subplot(111)
#res = ax.imshow(array(norm_conf), cmap=cm.jet, interpolation='nearest')
#cb = fig.colorbar(res)

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)

enter image description here

Community
  • 1
  • 1
Lucas
  • 6,869
  • 5
  • 29
  • 44