-
-
Save ClementC/acf8d5f21fd91c674808 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.metrics import confusion_matrix | |
def print_cm(cm, labels): | |
"""pretty print for confusion matrixes""" | |
columnwidth = max([len(x) for x in labels]) | |
# Print header | |
print(" " * columnwidth, end="\t") | |
for label in labels: | |
print("%{0}s".format(columnwidth) % label, end="\t") | |
print() | |
# Print rows | |
for i, label1 in enumerate(labels): | |
print("%{0}s".format(columnwidth) % label1, end="\t") | |
for j in range(len(labels)): | |
print("%{0}d".format(columnwidth) % cm[i, j], end="\t") | |
print() | |
# first generate with specified labels | |
labels = [ ... ] | |
cm = confusion_matrix(ypred, y, labels) | |
# then print it in a pretty way | |
print_cm(cm, labels) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adapted for Python 3