from sklearn.metrics import confusion_matrix
y_true = [2, 0, 2, 2, 0, 1]
y_pred = [0, 0, 2, 2, 0, 2]
c=confusion_matrix(y_true, y_pred)
print(c)
结果:
[[2 0 0]
[0 0 1]
[1 0 2]]
对这个矩阵的理解,画了图
参数 normalize 可选值有:{'true', 'pred', 'all'}
这个参数值可以使用百分率来代替个数。true,pred,all 分别表示以每行,每列,所有元素和为整体(整体占有率为1)