首页 > 编程语言 >准确率为0.81的程序

准确率为0.81的程序

时间:2022-12-02 15:00:43浏览次数:31  
标签:fft torch 程序 feature label 准确率 0.81 test out

因为我观察了baseline错误分类数据的频域发现,他们的振幅所处的频率相同,因此我想用振幅比较大对应的频率来分。我选择这些数据中振幅大于0.1的振幅对应的频率。需要改进的地方可能是应该采取所有训练集中大于0.1振幅的频率。

 

 

import matplotlib.pyplot as plt import numpy as np import pandas as pd import torch import torch.fft as fft df = pd.read_csv('train.csv') df=df.drop(['ID'],axis=1) nmp=df.to_numpy() feature=nmp[:-20,:-1] label=nmp[:-20,-1]#(210,240) feature=torch.fft.fft(torch.Tensor(feature)) feature=torch.abs(feature)/240*2 feature=feature[:,[0, 1, 60, 180, 239, 59, 120, 181, 61, 179, 119, 121, 58, 182, 57, 183, 62, 178]] test_feature=nmp[-20:,:-1] test_label=nmp[-20:,-1]#(210,240)
test_feature=torch.fft.fft(torch.Tensor(test_feature)) test_feature=torch.abs(test_feature)/240*2 test_feature=test_feature[:,[0, 1, 60, 180, 239, 59, 120, 181, 61, 179, 119, 121, 58, 182, 57, 183, 62, 178]] from torch import nn import torch loss=nn.MSELoss() feature=torch.Tensor(feature) label=torch.Tensor(label) label=label.reshape(-1,1)
test_feature=torch.Tensor(test_feature) test_label=torch.Tensor(test_label) test_label=test_label.reshape(-1,1)
network=nn.Sequential(nn.Linear(18,5),nn.Sigmoid(),nn.Linear(5,1),nn.Sigmoid()) import torch.optim as optim optimizer = optim.Adam(network.parameters(), lr=0.004) for epoch in range(10000):     optimizer.zero_grad()     out=network(feature)     l=loss(out,label)     l.backward()     optimizer.step()     Y = torch.ge(out, 0.5).float()     acc=Y.eq(label).float().sum()/len(label)     out=network(test_feature)     Y = torch.ge(out, 0.5).float()     test_acc=Y.eq(test_label).float().sum()/len(test_label)     print(epoch,l,acc,test_acc)     #if test_acc==0.50 and acc>0.93:     if acc>0.83 and test_acc==0.85:         break
df = pd.read_csv('test.csv') df=df.drop(['ID'],axis=1) nmp=df.to_numpy() feature=nmp[:,:] feature=torch.fft.fft(torch.Tensor(feature)) feature=torch.abs(feature)/240*2 feature=torch.Tensor(feature[:,[0, 1, 60, 180, 239, 59, 120, 181, 61, 179, 119, 121, 58, 182, 57, 183, 62, 178]]) out=network(feature) out=out.detach().numpy() out=out>0.5 out=out.astype(np.int) out=pd.DataFrame(out) out.columns = ['CLASS'] w=[] for k in range(out.shape[0]):     w.append(k+210) out['ID']=np.reshape(w,(-1,1)) out[['ID','CLASS']].to_csv('out.csv',index=False)

标签:fft,torch,程序,feature,label,准确率,0.81,test,out
From: https://www.cnblogs.com/hahaah/p/16944503.html

相关文章