cm_plot.py

# cm_plot.py 文件,包括了混淆矩阵可视化函数,
# 放置在python的site-packages 目录,供调用
# 例如:~/anaconda2/lib/python2.7/site-packages
#-*- coding: utf-8 -*-
def cm_plot(y, yp):
  from sklearn.metrics import confusion_matrix #导入混淆矩阵函数
  cm = confusion_matrix(y, yp) #混淆矩阵
  import matplotlib.pyplot as plt #导入作图库
  plt.matshow(cm, cmap=plt.cm.Greens) #画混淆矩阵图,配色风格使用cm.Greens,更多风格请参考官网。
  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') #坐标轴标签
  return plt
"""
作者:温故知新的骆驼
链接:https://www.jianshu.com/p/498ea0d8017d
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
"""

# 程序文件ex2_53.py import pandas as pd import matplotlib.pyplot as plt plt.rcParams.update({ 'font.family': 'sans-serif', 'font.sans-serif': ['DejaVu Sans', 'SimHei'], 'font.size': 12, 'axes.labelsize': 14, 'axes.titlesize': 16, 'mathtext.fontset': 'cm', 'figure.figsize': (8, 6), 'grid.alpha': 0.3, 'figure.dpi': 150, 'savefig.dpi': 300, 'axes.unicode_minus': False }) a = pd.read_excel("data2_52.xlsx", header=None) b = a.T b.plot(kind='bar') plt.legend(['钻石', '铂金']) plt.xticks(range(6), b[0], rotation=0) plt.show() 报错如下: "D:\develop\Python\Python 3.13.2\python.exe" "D:\develop\Python\PythonStudy\《Python数学建模算法与应用》程序和数据\02第2章 Python使用入门\ex2_53.py" D:\develop\Python\PyCharm 2024.3.2\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:82: UserWarning: Glyph 26376 (\N{CJK UNIFIED IDEOGRAPH-6708}) missing from font(s) DejaVu Sans. D:\develop\Python\PyCharm 2024.3.2\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:82: UserWarning: Glyph 38075 (\N{CJK UNIFIED IDEOGRAPH-94BB}) missing from font(s) DejaVu Sans. D:\develop\Python\PyCharm 2024.3.2\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:82: UserWarning: Glyph 30707 (\N{CJK UNIFIED IDEOGRAPH-77F3}) missing from font(s) DejaVu Sans. D:\develop\Python\PyCharm 2024.3.2\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:82: UserWarning: Glyph 38082 (\N{CJK UNIFIED IDEOGRAPH-94C2}) missing from font(s) DejaVu Sans. D:\develop\Python\PyCharm 2024.3.2\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:82: UserWarning: Glyph 37329 (\N{CJK UNIFIED IDEOGRAPH-91D1}) missing from font(s) DejaVu Sans. D:\develop\Python\PyCharm 2024.3.2\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:85: UserWarning: Glyph 26376 (\N{CJK UNIFIED IDEOGRAPH-6708}) missing from font(s) DejaVu Sans. D:\develop\Python\PyCharm 2024.3.2\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:85: UserWarning: Glyph 38075 (\N{CJK UNIFIED IDEOGRAPH-94BB}) missing from font(s) DejaVu Sans. D:\develop\Python\PyCharm 2024.3.2\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:85: UserWarning: Glyph 30707 (\N{CJK UNIFIED IDEOGRAPH-77F3}) missing from font(s) DejaVu Sans. D:\develop\Python\PyCharm 2024.3.2\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:85: UserWarning: Glyph 38082 (\N{CJK UNIFIED IDEOGRAPH-94C2}) missing from font(s) DejaVu Sans. D:\develop\Python\PyCharm 2024.3.2\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:85: UserWarning: Glyph 37329 (\N{CJK UNIFIED IDEOGRAPH-91D1}) missing from font(s) DejaVu Sans. 进程已结束,退出代码为 0
03-17
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值