使用svm做运动分类

linear:线性核函数,是在数据线性可分的情况下使用的,运算速度快,效果好。不足在于它不能处理线性不可分的数据。(在本例中C设为100,换为这个核函数之后的准确率为:0.8595317725752508)

poly:多项式核函数,多项式核函数可以将数据从低维空间映射到高维空间,但参数比较多,计算量大。(在本例中C设为100,换为这个核函数之后的准确率为:0.8729096989966555)

rbf:高斯核函数(默认),高斯核函数同样可以将样本映射到高维空间,但相比于多项式核函数来说所需的参数比较少,通常性能不错,所以是默认使用的核函数。(在本例中C设为100,换为这个核函数之后的准确率为:0.9230769230769231)

sigmoid:sigmoid 核函数,sigmoid 经常用在神经网络的映射中。因此当选用 sigmoid 核函数时,SVM 实现的是多层神经网络。(在本例中C设为100,换为这个核函数之后的准确率为:0.7324414715719063)
————————————————
svm的核参数。

其实一维神经网络就不太好用,所以用线性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)
posted @   祥瑞哈哈哈  阅读(53)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
历史上的今天:
2021-12-04 IP
点击右上角即可分享
微信分享提示