sklearn.metrics.confusion_matrix

①混淆矩阵: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()
   ...:


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值