forked from dionny/ai-for-testing-binder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfusion_matrix.py
More file actions
28 lines (20 loc) · 798 Bytes
/
confusion_matrix.py
File metadata and controls
28 lines (20 loc) · 798 Bytes
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
"""Pretty-prints a confusion matrix."""
def print_cm(cm, labels):
""" Pretty-prints a confusion matrix.
:param cm: The confusion matrix.
:param labels: A list of labels to map classification indices to human-readable labels.
"""
print("Confusion Matrix")
column_width = max([len(x) for x in labels] + [5]) # 5 is value length
empty_cell = " " * column_width
print(" " + empty_cell, end=" ")
for label in labels:
print("%{0}s".format(column_width) % label, end=" ")
print()
for i, label1 in enumerate(labels):
print(" %{0}s".format(column_width) % label1, end=" ")
for j in range(len(labels)):
cell = "%{0}.1f".format(column_width) % cm[i, j]
print(cell, end=" ")
print()
print()