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


    # SVM支持向量机和逻辑回归进行心音信号简单二分类 matlab实现:
    %%
    %本程序读取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
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72

    分类结果:

    accuracy =
    
        76
    • 1
    • 2
    • 3

    这里写图片描述
    由于只采用了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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30

    转载 原文地址:http://blog.csdn.net/michaelpixer/article/details/54947769

  • 相关阅读:
    bash的shebang行
    Step By Step(Lua调用C函数)
    [Android问答] px、dp和sp,这些单位有什么区别?
    Android中Application类用法
    Android中SharedPreferences用法
    Android中SQLite用法
    SQLite应用实例
    Android中Parcelable接口用法
    iOS block 基本用法及代替代理
    Xcode插件
  • 原文地址:https://www.cnblogs.com/siucaan/p/9623225.html
Copyright © 2020-2023  润新知