Created
January 25, 2018 11:50
-
-
Save Idan707/f9baad46693375282439eae8dde4f55a 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 numpy as np | |
import itertools | |
from sklearn.metrics import confusion_matrix | |
def plot_confusion_matrix(cm, classes, | |
normalize=False, | |
title='Confusion matrix', | |
cmap=plt.cm.winter): | |
if normalize: | |
cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis] | |
plt.imshow(cm, interpolation='nearest', cmap=cmap) | |
plt.title(title, fontsize=30) | |
plt.colorbar() | |
tick_marks = np.arange(len(classes)) | |
plt.xticks(tick_marks, classes, fontsize=20) | |
plt.yticks(tick_marks, classes, fontsize=20) | |
fmt = '.2f' if normalize else 'd' | |
thresh = cm.max() / 2. | |
for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])): | |
plt.text(j, i, format(cm[i, j], fmt), horizontalalignment="center", | |
color="white" if cm[i, j] < thresh else "black", fontsize=40) | |
plt.tight_layout() | |
plt.ylabel('True label', fontsize=30) | |
plt.xlabel('Predicted label', fontsize=30) | |
return plt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment