【问题标题】:Plot a confusion matrix with meaningful row and column labels绘制具有有意义的行和列标签的混淆矩阵
【发布时间】:2021-01-17 04:04:24
【问题描述】:

关于我的混淆矩阵布局的问题。我想将变量标签对应的数字“0”、“1”和“2”替换为“裸土”、“玉米”和“其他作物”的实际变量标签。 感谢您的帮助。

CM = confusion_matrix(y_test, y_pred)
CM = sns.heatmap(CM, square = True, cmap = "coolwarm", linewidths = .5, annot = True)
plt.title('Model confusion matrix', fontsize = 20) 
plt.xlabel('Predict', fontsize = 15) 
plt.ylabel('Real', fontsize = 15) 
plt.show()

【问题讨论】:

标签: python dataframe layout label confusion-matrix


【解决方案1】:

试试plt.yticksplt.xticks

import matplotlib.pyplot as plt
sns.heatmap(confusion_matrix(y_test,y_pred),annot=True)
plt.yticks(np.arange(3)+0.5,('X1','X2','X3'), fontsize="10")
plt.xticks(np.arange(3)+0.5,('X1','X2','X3'), fontsize="10" )

Source

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-14
    • 2020-10-24
    • 2021-09-20
    • 2016-01-31
    • 1970-01-01
    • 1970-01-01
    • 2020-01-22
    相关资源
    最近更新 更多