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 混入的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
- mysqli获取所有数据 mysql的提取函数
- mysql 分组函数 mysql分组取数据
- mysql统计函数
- mysql有rank函数吗 mysql有rank
- mongdb python pythonmongodb操作
- redis-cli命令不能用 redis函数调用失败
- mysql的判断函数 mysql怎么判断奇偶数
- mysql数据库编码格式查询 mysql编码函数
- mysql日期yyyymmdd mysql中的日期型函数
- mysql序列函数 mysql如何查序列
