DSP

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

2019-07-13 21:03发布

%% %本程序读取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)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 分类结果: accuracy = 76 这里写图片描述
由于只采用了150个信号做训练集,训练好的分类器只有76%的预测率,心音信号来源于https://physionet.org/physiobank/database/challenge/2016/training.zip
REFERENCE.csv形式:
这里写图片描述
特征提取函数feature_extraction采用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