使用seaborn/matplotlib定制好看的confusion matrix
使用Python seaborn/matplotlib结合pretty-print-confusion-matrix可以制作好看的confusion matrix了。
import numpy as np
import pandas as pd
from pretty_confusion_matrix import pp_matrix #调用pp_matrix#pandas dataframe数据准备
array = np.array([[13, 0, 1, 0, 2, 0],[0, 50, 2, 0, 10, 0],[0, 13, 16, 0, 0, 3],[0, 0, 0, 13, 1, 0],[0, 40, 0, 1, 15, 0],[0, 0, 0, 0, 0, 20]])df_cm = pd.DataFrame(array, index=range(1, 7), columns=range(1, 7))
pp_matrix(df_cm, cmap='PuRd') #matrix plot
import numpy as np
from pretty_confusion_matrix import pp_matrix_from_data#vector数据准备
y_test = np.array([1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2,3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5])
predic = np.array([1, 2, 4, 3, 5, 1, 2, 4, 3, 5, 1, 2, 3, 4, 4, 1, 4, 3, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 3, 3, 5, 1, 2, 3, 3, 5, 1, 2,3, 4, 4, 1, 2, 3, 4, 1, 1, 2, 3, 4, 1, 1, 2, 3, 4, 1, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5])pp_matrix_from_data(y_test, predic)
pretty-print-confusion-matrix安装
pip install pretty-confusion-matrix