python混淆函数 python 混入( 二 )


import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix
def confusion_matrix_plot_matplotlib(y_truth, y_predict, cmap=plt.cm.Blues):
"""Matplotlib绘制混淆矩阵图
parameters
----------
y_truth: 真实python混淆函数的y的值, 1d array
y_predict: 预测的y的值, 1d array
cmap: 画混淆矩阵图的配色风格, 使用cm.Bluespython混淆函数,更多风格请参考
"""
cm = confusion_matrix(y_truth, y_predict)
plt.matshow(cm, cmap=cmap)# 混淆矩阵图
plt.colorbar()# 颜色标签
for x in range(len(cm)):# 数据标签
for y in range(len(cm)):
plt.annotate(cm[x, y], xy=(x, y), horizontalalignment='center', verticalalignment='center')
plt.ylabel('True label')# 坐标轴标签
plt.xlabel('Predicted label')# 坐标轴标签
plt.show()# 显示作图结果
if __name__ == '__main__':
y_truth = [1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]
y_predict = [1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0]
confusion_matrix_plot_matplotlib(y_truth, y_predict)
关于python混淆函数和python 混入的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

推荐阅读