plot confusion matrix function deep learning

Solutions on MaxInterview for plot confusion matrix function deep learning by the best coders in the world

showing results for - "plot confusion matrix function deep learning"
Sarah
09 May 2019
1def plot_confusion_matrix(cm, classes,
2                        normalize=False,
3                        title='Confusion matrix',
4                        cmap=plt.cm.Blues):
5    """
6    This function prints and plots the confusion matrix.
7    Normalization can be applied by setting `normalize=True`.
8    """
9    plt.imshow(cm, interpolation='nearest', cmap=cmap)
10    plt.title(title)
11    plt.colorbar()
12    tick_marks = np.arange(len(classes))
13    plt.xticks(tick_marks, classes, rotation=45)
14    plt.yticks(tick_marks, classes)
15
16    if normalize:
17        cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
18        print("Normalized confusion matrix")
19    else:
20        print('Confusion matrix, without normalization')
21
22    print(cm)
23
24    thresh = cm.max() / 2.
25    for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):
26        plt.text(j, i, cm[i, j],
27            horizontalalignment="center",
28            color="white" if cm[i, j] > thresh else "black")
29
30    plt.tight_layout()
31    plt.ylabel('True label')
32    plt.xlabel('Predicted label')