Created
August 5, 2019 13:58
-
-
Save nerdinand/748192be1bc69d7e39e043ace5451527 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
import turicreate as tc | |
import pandas as pd | |
def print_human_confusion_matrix(actual, predicted): | |
cf_matrix = tc.evaluation.confusion_matrix(actual, predicted) | |
labels = list(set(cf_matrix['predicted_label'].append(cf_matrix['target_label']))) | |
matrix = [] | |
for predicted_label in labels: | |
out_row = [] | |
for target_label in labels: | |
row = cf_matrix[(cf_matrix['predicted_label']==predicted_label) & (cf_matrix['target_label']==target_label)] | |
out_row.append(row['count']) | |
matrix.append(out_row) | |
print(pd.DataFrame(matrix, index=labels, columns=labels)) | |
actual = tc.SArray(["blue", "red", "silver", "silver", "red", "silver", "blue", "red"]) | |
predicted = tc.SArray(["blue", "red", "blue", "silver", "red", "blue", "silver", "silver"]) | |
print_human_confusion_matrix(actual, predicted) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment