SVM支持向量机和逻辑回归进行心音信号简单二分类

2020-05-15更新
鉴于最近关注这个的朋友比较多,好多反映数据失效,之前由于备份硬盘坏了疫情原因也一直没去修,没回复大家,今天找了一下原数据网站的归档地址,新的数据下载地址:
https://archive.physionet.org/physiobank/database/challenge/2016/training.zip
同时也对内容进行补充完善一下,方便大家学习交流
详细分析报告链接:https://pan.baidu.com/s/1n25_z7-ysTRDMva8Elio5A 密码:lph0


1. 要求:

将给定的心音信号分类为正常,异常(即他们需要专家进一步评估以进一步评估或潜在治疗),或者过于嘈杂或模糊三类以进行评估,尽量提高准确率。
程序分为main.mfeature_extraction.m两个文件

2. 程序:

特征提取函数feature_extraction.m采用db6小波特征提取,函数代码如下:

function [ ss ] = feature_extraction(route )
% [x,fs]=audioread('./training-a/a0001.wav');
[x,fs]=audioread(route);
x1=x(:,1); % 抽取第 1 声道
level = 4;
wname ='db6';%选取小波
t=wpdec(x1,level,wname,'shannon');%小波分解
% plot(t);

t0=wprcoef(t,[3,0]);
t1=wprcoef(t,[4,2]);
t2=wprcoef(t,[4,3]);
t3=wprcoef(t,[3,2]);
t4=wprcoef(t,[4,6]);
t5=wprcoef(t,[4,7]);
t6=wprcoef(t,[1,1]);

%构建特征向量
s0=norm(t0);
s1=norm(t1);
s2=norm(t2);
s3=norm(t3);
s4=norm(t4);
s5=norm(t5);
s6=norm(t6);
ss=[s0,s1,s2,s3,s4,s5,s6];%得到7维的特征向量
%  figure();
%  bar(ss);
 end
 

main.m函数如下:

%%
%本程序读取training-a中150个心音信号作为训练集,后150个心音信号作为测试数据,采用SVM支持向量机和逻辑回归分类器
%进行心音信号的分类
%%
clear;
clc;
rng=[0 1 149 1];%训练 rng=[r1 c1 r2 c2]定义读取csv文件的行列始末段
rng1=[150 1 299 1];%测试
train_label=csvread('./training-a/REFERENCE.csv',0,1,rng);%读取训练标签
for i=1:length(train_label)
    if train_label(i)<0
        train_label(i)=2;
    end
end

test_label=csvread('./training-a/REFERENCE.csv',150,1,rng1);%读取测试标签
for i=1:length(test_label)
    if test_label(i)<0
        test_label(i)=2;
    end
end
figure();
subplot(211);
bar(test_label);%画出测试数据的正确分类标签
%%
%对原始数据进行特征提取,构建n维的训练数据矩阵,样本大小为150
train_data=[];
test_data=[];
for i=1:9
    ss=feature_extraction(strcat('./training-a/a000',num2str(i),'.wav'));
    train_data=[train_data;ss];
end
for i=10:99
    ss=feature_extraction(strcat('./training-a/a00',num2str(i),'.wav'));
    train_data=[train_data;ss];
end
for i=100:150
    ss=feature_extraction(strcat('./training-a/a0',num2str(i),'.wav'));
    train_data=[train_data;ss];
end
%对原始数据进行特征提取,构建n维的测试数据矩阵
for i=151:300
    ss=feature_extraction(strcat('./training-a/a0',num2str(i),'.wav'));
    test_data=[test_data;ss];
end

%%
%SVM支持向量机分类器
% Factor = svmtrain( train_data,train_label);
% predict_label = svmclassify(Factor, test_data);
% accuracy = length(find(predict_label == test_label))/length(test_label)*100;
% accuracy
% subplot(212);
% bar(predict_label);%绘制预测矩阵与正确答案进行比较

%逻辑回归
Factor = mnrfit(train_data, train_label);
Scores = mnrval(Factor, test_data);
S1=Scores(:,1);
S2=Scores(:,2);
predict_label=[];
for i=1:length(S1)
    if S1(i)<S2(i)
        predict_label=[predict_label;2];
    else
        predict_label=[predict_label;1];
    end
end
subplot(212);
bar(predict_label);
accuracy = length(find(predict_label == test_label))/length(test_label)*100;
accuracy

3. 分类结果:

使用training-a样本中前150个心音信号样本数据作为训练数据,后150个作为测试数据。

(1)SVM支持向量机的分类结果及准确率:

在这里插入图片描述
图1 SVM正确答案(上)与分类结果(下)对比
在这里插入图片描述
图2 SVM分类准确率

(2)逻辑回归的分类结果及准确率:

这里写图片描述
图3 逻辑回归分类器正确答案(上)与分类结果(下)对比
在这里插入图片描述
图4 逻辑回归分类准确率

由于只采用了150个信号做训练集,训练好的分类器只有76%的预测率,心音信号来源于https://physionet.org/physiobank/database/challenge/2016/training.zip
REFERENCE.csv形式:
这里写图片描述

  • 7
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 16
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值