画混淆矩阵

import numpy as np  
import matplotlib.pyplot as plt 

classes = ["Normal", "Benign", "Insitu", "Invasive"]
yClasses = ["", "Normal", "Benign", "Insitu", "Invasive", ""]
confusion_matrix = np.array([[1.0, 0.0, 0.0, 0.0],
                             [0.0, 1.0, 0.0, 0.0],
                             [0.07, 0.0, 0.86, 0.07],
                             [0.0, 0.04, 0.04, 0.92]])

plt.imshow(confusion_matrix, interpolation = "nearest", cmap = plt.cm.Blues)
plt.title("Normalized confusion_matrix")
plt.colorbar()
tick_marks = np.array([0.0, 1.0, 2.0, 3.0, 4.0])
plt.xticks([0, 1, 2, 3], classes)
plt.yticks([-0.5, 0.0, 1.0, 2.0, 3.0, 3.5], yClasses)

thresh = confusion_matrix.max() / 2.
iters = np.reshape([[[i, j] for j in range(4)] for i in range(4)], (confusion_matrix.size, 2))
for i, j in iters:
    plt.text(j, i, format(confusion_matrix[i, j]))
plt.ylabel("Real label")
plt.xlabel("Prediction")
plt.tight_layout()
plt.savefig("confusion_matrix.png")

来源: https://www.cnblogs.com/Tom-Ren/p/10234960.html

你可能感兴趣的:(画混淆矩阵)