欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

sklearn.metrics.confusion_matrix

程序员文章站 2022-05-23 23:19:50
...
①混淆矩阵:sklearn.metrics.confusion_matrix(y_true, y_pred, labels=None, sample_weight=None)
参数说明:
y_true:真实因变量值
y_pred:预测因变量值
labels:矩阵的标签列表索引顺序
sample_weight:样本权重
In [3]: from sklearn.metrics import confusion_matrix
   ...: from matplotlib.font_manager import FontProperties
   ...: import matplotlib.pyplot as plt
   ...: import numpy as np
   ...: font = FontProperties(fname=r"c:\windows\fonts\msyh.ttc", size=10)
   ...: y_true = ['cat', 'ant', 'cat', 'cat', 'ant', 'bird']
   ...: y_pred = ['ant', 'ant', 'cat', 'cat', 'ant', 'cat']
   ...: labels = ['ant', 'bird','cat']
   ...: maxtrix = confusion_matrix(y_true, y_pred,labels=labels)
   ...: plt.matshow(maxtrix)
   ...: plt.colorbar()
   ...: plt.xlabel('预测类型',fontproperties=font)
   ...: plt.ylabel('实际类型',fontproperties=font)
   ...: plt.xticks(np.arange(maxtrix.shape[1]),labels)
   ...: plt.yticks(np.arange(maxtrix.shape[1]),labels)
   ...: plt.show()
   ...:
sklearn.metrics.confusion_matrix