-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconf-table.py
executable file
·45 lines (34 loc) · 1.05 KB
/
conf-table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
import sys
from sklearn.metrics import confusion_matrix
from scipy.sparse.csgraph import reverse_cuthill_mckee
def read_labels(f):
with open(f) as fp:
lab = []
for line in fp:
lab.append(int(line.strip()))
return lab
# def maximize_diag(m):
# no_diag = dict()
# for i in range(m.shape[0]):
# for j in range(i+1, m.shape[0]):
# print(i, j)
# no_diag[(i,j)] = m[i,j] + m[j,i]
# return no_diag
gold = read_labels(sys.argv[1])
pred = read_labels(sys.argv[2])
# gold = read_labels("data/es_test.labels")
# pred = read_labels("results/svm-spanish.output.txt")
labels = sorted(set(gold))
cm = confusion_matrix(gold, pred)
# labels = ["\\emoji{{es}}{{{}}}".format(x) for x in labels]
# fmt = "{:>3}" + "&{:>4}" * len(labels)
# print(fmt.format(" ", *labels))
# for i, row in enumerate(cm):
# print(fmt.format(labels[i], *row))
#
print("x,y,v")
for i in range(cm.shape[0]):
for j in range(cm.shape[1]):
print ("{},{},{}".format(i, j, cm[i,j]))
print()