心脏病预测

实验基础信息

  • 实验名称:心脏病预测

  • 实验英文名:HeartDiseasePrediction

  • 所属类目:智慧医疗

  • 实验描述:根据体检指标,年龄、性别、胸部疼痛类型、血压、胆固醇、空腹血糖、心电图结果、是否心绞痛等预测用户是否会患心脏病

  • 主要应用算法:逻辑回归二分类

数据说明

  • 数据来源:开源数据。

  • 数据属性:结构化数据。

  • 数据详情:数据集为用户体检信息,包含年龄、性别、胸部疼痛类型、血压、胆固醇、空腹血糖、心电图结果、是否心绞痛等列

实验搭建

实验整体流程如下:

2020 12 13 15 13 25
  • 读数据表:读入用户原始体检数据。

2020 12 13 15 13 55
  • SQL脚本:进行数据映射,将字符类型的枚举值映射为数值类型,如男性映射为1,女性映射为0。

select
    age         ,
    (case sex
        when 'male' then 1
        else 0
    end) as sex         ,
    (case cp
        when 'angina' then 0
        when 'notang' then 1
        else 2
    end) as cp         ,
    trestbps         ,
    chol         ,
    (case fbs
        when 'true' then 1
        else 0
    end) as fbs         ,
    (             case restecg
        when 'norm' then 0
        when 'abn' then 1
        else 2
    end         ) as restecg         ,
    thalach         ,
    (case exang
        when 'true' then 1
        else 0
    end) as exang         ,
    oldpeak         ,
    (case slop
        when 'up' then 0
        when 'flat' then 1
        else 2
    end) as slop         ,
    ca         ,
    (case thal
        when 'norm' then 0
        when 'fix' then 1
        else 2
    end) as thal         ,
    (case status
        when 'sick' then 1
        else 0
    end) as ifHealth
from
    ${table2};
  • 类型转化:将表中int类型数据,全部转化为double类型,方便后续运算。

2020 12 13 15 14 24
  • 归一化:对表的数据列进行归一化处理,采用线性函数转化,计算表达式为y=(x-min)/(max-min),归一化至[0,1]之间。

2020 12 13 15 14 54
  • 拆分:将数据按照8:2拆分成训练数据与测试数据。

  • 逻辑回归二分类;采用逻辑回归二分类算法,训练分类模型。

    • 逻辑回归二分类组件:用于预测当前被观察的对象属于哪个组,最终提供离散的二进制(0或1)输出结果。

2020 12 13 15 15 25
  • 预测:用训练好的模型预测测试数据,预测结果如下。

2020 12 13 15 15 58
  • 二分类评估:利用评估组件,进行模型评价,AUC准确率为86.36%,效果较好。

2020 12 13 15 16 29
2020 12 13 15 17 10