当前位置:   article > 正文

python画信号数据的混淆矩阵_sphinx-gallery

sphinx-gallery

混淆矩阵数据
混淆矩阵


import matplotlib
import matplotlib.pyplot as plt
# sphinx_gallery_thumbnail_number = 2
import pandas as pd
import numpy as np
from matplotlib.ticker import MultipleLocator, FormatStrFormatter

d="EMD"   ##i 可选项IQ、EMD、VMD
f=8    ##j 可选项4、6、8
k=0.5    ##k 可选项1、0.5、0.1
datapath="./data/{}_test/sample{}/resnet{}/".format(d,k,f)
datasave="./hunxiao_pdf/{}/sample{}/".format(d,k)
data=pd.read_csv(datapath+"label.csv")
pre=data['识别标签']
true=data['原始标签']
pre=np.array(pre)
true=np.array(true)
#生成12个计数变量a0~到a11
a=np.zeros((12,12),dtype=int)

##从csv文件中获得混淆矩阵数据
for i in range(26):
    start=int(i*13000)
    end=int((i+1)*13000)
    pre1=pre[start:end]
    true1=true[start:end]
    for j in range(len(pre1)):
        for z in range(12):

            if pre1[j]==z:
                a[i][z]=int(a[i][z])+1
print(a)
a=np.array(a)

plt.rc('font',family='Times New Roman')
# 热度图,后面是指定的颜色块,可设置其他的不同颜色
font = {'family': 'Times New Roman',
         'weight': 'normal',
         'size': 8,
         }
font1 = {'family': 'Times New Roman',
         'weight': 'normal',
         'size': 10,
         }
###设置每个子图大小
fig, ax = plt.subplots(figsize=(7,7))
# plt.figure(figsize=(5, 5))
##画布颜色
# plt.imshow(a,cmap=plt.cm.Blues)
im = ax.imshow(a,cmap=plt.cm.Blues,)

##设置坐标轴刻度

classes=['BPSK','QPSK','8PSK','OQPSK','2FSK','4FSK','8FSK','16QAM','32QAM','64QAM','4PAM','8PAM']
# We want to show all ticks...

###设置x,y轴长度
ax.set_xticks(np.arange(len(classes)))
ax.set_yticks(np.arange(len(classes)))
# ... and label them with the respective list entries
ax.set_xticklabels(classes,fontdict=font)
ax.set_yticklabels(classes,fontdict=font)

plt.xlabel('Predicted label', font1)
plt.ylabel('True lable', font1)

# Rotate the tick labels and set their alignment.
plt.setp(ax.get_xticklabels(), rotation=45, ha="right",
         rotation_mode="anchor")

# Loop over data dimensions and create text annotations.
for i in range(len(classes)):
    for j in range(len(classes)):
        text = ax.text(j, i, a[i, j],
                       ha="center", va="center", color="brown",)

# ax.set_title("data of local classes (in tons/year)")
fig.tight_layout()
plt.savefig(datasave+'resnet{}.pdf'.format(f), bbox_inches='tight')
plt.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/在线问答5/article/detail/742916
推荐阅读
相关标签
  

闽ICP备14008679号