-
-
Save ariffyasri/fb6c76df29a1112c023625f682a8cd97 to your computer and use it in GitHub Desktop.
This file contains 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""" | |
# using str in len because of some label | |
# may using integer as label | |
columnwidth = max([len(str(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