3.print()函数

该代码读取多个文件中的数据,将数据整合并写入新的文件中。然后,它从新文件中提取数据,用于创建一个折线图和散点图,显示当前、top1和top5的精度随训练轮数(Epoch)的变化情况。图表清晰地展示了各个指标在不同Epoch的表现。
摘要由CSDN通过智能技术生成
import numpy as np
import matplotlib.pyplot as plt
with open('C:\\Users\\dell\\Desktop\\shujuji.txt', 'w+') as fd:
    with open('C:\\Users\\dell\\Desktop\\accuracy.txt', 'r') as fa:
        with open('C:\\Users\\dell\\Desktop\\top1.txt', 'r') as fb:
            with open('C:\\Users\\dell\\Desktop\\top5.txt', 'r') as fc:
                i=0
                for line in fa:
                    i=i+1
                    linea=line.strip('\r\n')
                    lineb=fb.readline()
                    linec=fc.readline()
                    fd.write(str(i)+" "+linea+" "+lineb.strip('\r\n')+" "+linec.strip('\r\n'))
                    fd.write("\n")

x = []
y1 = []
y2 = []
y3 = []

with open("C:\\Users\\dell\\Desktop\\shujuji.txt","r")as fd:
    for line in fd:
        line = line.strip('\n')
        line = line.split(' ')
        x.append(float(line[0]))
        y1.append(float(line[1]))
        y2.append(float(line[2]))
        y3.append(float(line[3]))
    
plt.plot(x,y1,c='royalblue', label="current") 
plt.plot(x,y2,c='coral',label="top1")  
plt.plot(x,y3,c='black',label="top5")  # 画线

plt.scatter(x,y1,c='royalblue')
plt.scatter(x,y2,c='coral') 
plt.scatter(x,y3,c='black')   # 画点

plt.legend(loc='best',frameon=False) # 图例边框

plt.xticks(range(0, 21, 1))
plt.yticks(range(0, 110,10))# x,y轴刻度

plt.xlabel("Epoch", fontdict={'size': 16})
plt.ylabel("Percentage%", fontdict={'size': 16})
plt.title("评价标准图", fontdict={'size': 20})
plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值