def PlotConfusionMatrix(confusion):
  labels = set()
  for ((label,guess), count) in confusion.items():
    labels.add(label)
    labels.add(guess)
  labels = [x for x in labels]
  def correct(a, b):
    return 1 if a == b else -1
  mat = [[confusion[labels[i],labels[j]]*correct(i, j) for j in range(len(labels))] for i in range(len(labels))]
  graph.hinton(np.array(mat), title="Confusion matrix", vlabels=labels, hlabels=labels)
Exemplo n.º 2
0
def PlotConfusionMatrix(confusion):
    labels = set()
    for ((label, guess), count) in confusion.items():
        labels.add(label)
        labels.add(guess)
    labels = [x for x in labels]

    def correct(a, b):
        return 1 if a == b else -1

    mat = [[
        confusion[labels[i], labels[j]] * correct(i, j)
        for j in range(len(labels))
    ] for i in range(len(labels))]
    graph.hinton(np.array(mat),
                 title="Confusion matrix",
                 vlabels=labels,
                 hlabels=labels)
Exemplo n.º 3
0
world = dataset.DiscreteDistribution([(1, dist) for cat,dist in rooms.items()])
test_samples = dataset.LabelledSample(world, TEST_SAMPLES)
#############################################################################

def map_classifier(sample):
  best = max([(dataset.SampleProbability(dist, sample), label) for label, dist in rooms.items()])
  return best[1]


confusion = collections.defaultdict(int)
for label, sample in map(dataset.ExtractLabel, test_samples):
  guess = map_classifier(sample)
  confusion[label, guess] += 1


'''Plot confusion matrix.'''
labels = set()
for ((label,guess), count) in confusion.items():
  labels.add(label)
  labels.add(guess)
labels = list(sorted(labels))
def correct(a, b):
  return 1 if a == b else -1
mat = [[confusion[labels[i],labels[j]]*correct(i, j) for j in range(len(labels))] for i in range(len(labels))]
graph.hinton(np.array(mat), title="Confusion matrix", vlabels=labels, hlabels=labels)

graph.savefig(OUTPUT)