其实一维神经网络就不太好用,所以用线性svm效果可能也不太好。
0 240 0.74 0.75
0.05 126 0.73 0.75
0.15 22 0.72 0.75
0.2 14 0.71 0.75
0.25 10 0.69 0.8
0.3 8 0.72 0.75
0.32 6 0.7 0.7
0.34 4 0.71 0.4
0.7 3 0.62 0.75
0.8 2 0.55 0.75
线性svm准确率是0.7即使用振幅选择特征。
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.detach().numpy() sum=1 li=[] for i in range(feature.shape[0]): index=feature[i,:]>=1.128 index=index.astype(np.int) index=np.nonzero(index)for j in index: for j1 in j: if j1 not in li: li.append(j1) print(li) print(len(li))
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[:,li] feature=feature.detach().numpy() 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[:,li] from torch import nn import torch label=label.reshape(-1,1) test_label=test_label.reshape(-1,1)
from sklearn import svm import matplotlib.pyplot as plt clf = svm.SVC(kernel = 'linear') # .SVC()就是 SVM 的方程,参数 kernel 为线性核函数 # 训练分类器 import sklearn from sklearn.metrics import accuracy_score clf.fit(feature, label) w=clf.predict(feature) pr=accuracy_score(label, w) print(pr)
w=clf.predict(test_feature) pr=accuracy_score(test_label, w) print(pr) 标签:fft,svm,分类,torch,feature,label,test,import,运动 From: https://www.cnblogs.com/hahaah/p/16950278.html