当前位置: 首页 > news >正文

python数据分析-心脏衰竭分析与预测

研究背景

人的心脏有四个瓣膜,主动脉银、二尖、肺动脉和三尖源 不管是那一个膜发生了病变,都会导致心脏内的血流受到影响,这就是通常所说的心脏期膜病,很多是需要通过手术的方式进行改善的。随着人口老龄化的加剧,,心脏期膜病是我国最常见的心血管疾病之-,需要接受心脏瓣膜手术治疗的患者数量逐年拳升。心脏期膜手术是对病变的心脏辨膜所进行的外科手术,一般包括心脏期的置换和修复手术,心期手术是在外科技术的基础上,对病变的心脏期膜所进行的手术,可以改善患者心脏期聘狭窄或关闭不全的现象。不过心脏瓣膜病手术可能会引发机械瓣并发症,导致心功能变差,严重的还会直接造成患者死亡。

实验分析

首先导入基本的数据分析包

# import data handling libsimport pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns# import modelsfrom sklearn.linear_model import LinearRegression, LogisticRegression
from sklearn.svm  import SVC
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import confusion_matrix, classification_report, accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifierimport warnings
warnings.filterwarnings('ignore')

读取数据

# Importing datasetdf = pd.read_csv('dataset.csv')

展示数据集和结构

df.head()
rows, columns = df.shapeprint(f"Number Of Rows : {rows}")
print(f"Number Of Columns : {columns}")

 

数据集特征结构

df.info()

描述性分析

df.describe()

查看每列的唯一值的数量 

df.nunique()

查看下相关系数并且画出热力图

plt.figure(figsize=(10, 8))
corr = df.corr()
sns.heatmap(corr, annot=True, cmap='Blues')

 查看缺失值

df.isnull().sum()

 接下来进行特征选择

plt.rcParams['figure.figsize']=15,6 
sns.set_style("darkgrid")x = df.iloc[:, :-1]
y = df.iloc[:,-1]from sklearn.ensemble import ExtraTreesClassifier
import matplotlib.pyplot as plt
model = ExtraTreesClassifier()
model.fit(x,y)
print(model.feature_importances_) 
feat_importances = pd.Series(model.feature_importances_, index=x.columns)
feat_importances.nlargest(12).plot(kind='barh', color='teal')
plt.show()

检查一下离群值

sns.boxplot(x = df.ejection_fraction, color='teal')
plt.show()

 

可以发现有两个离群值

接下来对特征进行可视化 

# Distribution of Ageimport plotly.graph_objects as gofig = go.Figure()
fig.add_trace(go.Histogram(x = df['age'],xbins=dict( # bins used for histogramstart=40,end=95,size=2),marker_color='#e8ab60',opacity=1
))fig.update_layout(title_text='AGE DISTRIBUTION',xaxis_title_text='AGE',yaxis_title_text='COUNT', bargap=0.05, # gap between bars of adjacent location coordinatesxaxis =  {'showgrid': False },yaxis = {'showgrid': False },template = 'plotly_dark'
)fig.show()

 

plt.style.use("seaborn")
for column in df.columns:if df[column].dtype!="object":plt.figure(figsize=(15,6))plt.subplot(2,2,1)sns.histplot(data=df,x=column,kde=True)plt.ylabel("freq")plt.xlabel(column)plt.title(f"distribution of {column}")plt.subplot(2,2,2)sns.boxplot(data=df,x=column)plt.ylabel(column)plt.title(f"boxplot of {column}")plt.show()

 

 接下来进行机器学习预测,划分训练集和测试集

逻辑回归

from sklearn.preprocessing import MinMaxScalerscaler = MinMaxScaler()x = scaler.fit_transform(x)
y = scaler.fit_transform(y.values.reshape(-1,1))
model = LogisticRegression()
model.fit(x_train, y_train)
y_pred = model.predict(x_test)
print(classification_report(y_test,y_pred))

决策树

支持向量机

plt.rcParams['figure.figsize']=15,6 
sns.set_style("darkgrid")
ax = sns.barplot(x=mylist2, y=mylist, palette = "rocket", saturation =1.5)
plt.xlabel("Classifier Models", fontsize = 20 )
plt.ylabel("% of Accuracy", fontsize = 20)
plt.title("Accuracy of different Classifier Models", fontsize = 20)
plt.xticks(fontsize = 12, horizontalalignment = 'center', rotation = 8)
plt.yticks(fontsize = 13)
for p in ax.patches:width, height = p.get_width(), p.get_height()x, y = p.get_xy() ax.annotate(f'{height:.2%}', (x + width/2, y + height*1.02), ha='center', fontsize = 'x-large')
plt.show()

 

完整代码和数据

创作不易,希望大家多点赞关注评论!!! 

相关文章:

  • stm32 启动文件分析
  • vsCode双击文件才能打开文件,单击文件只能预览?
  • 在Windows11系统上搭建SFTP服务器
  • 代码随想录算法训练营day43
  • MC服务器怎么搭建
  • 贪吃蛇游戏的编程之旅:在Windows PyCharm中使用Python
  • 【代码随想录】【算法训练营】【第28天】 [93]复原IP地址 [78]子集 [90]子集II
  • 【html】简单网页模板源码
  • 主流物联网协议客户端开源库介绍(mqtt,coap,websocket,httphttps,tcp及udp)
  • 关于头条项目经验的总结
  • Java 8 Stream 用法大全
  • 眼在手上的手眼标定(matlab+python)实测精度±1mm
  • 网络编程之XDP技术介绍
  • VFS:8.fd管理-fs/file.c源码阅读
  • Rockmongo详解:高效管理MongoDB的图形化利器
  • hexo+github搭建个人博客
  • JavaScript 如何正确处理 Unicode 编码问题!
  • Docker 1.12实践:Docker Service、Stack与分布式应用捆绑包
  • HTML中设置input等文本框为不可操作
  • node 版本过低
  • node-glob通配符
  • 初识 beanstalkd
  • 搞机器学习要哪些技能
  • 好的网址,关于.net 4.0 ,vs 2010
  • 技术:超级实用的电脑小技巧
  • 区块链共识机制优缺点对比都是什么
  • 手写双向链表LinkedList的几个常用功能
  • Redis4.x新特性 -- 萌萌的MEMORY DOCTOR
  • 摩拜创始人胡玮炜也彻底离开了,共享单车行业还有未来吗? ...
  • ​2020 年大前端技术趋势解读
  • #LLM入门|Prompt#2.3_对查询任务进行分类|意图分析_Classification
  • (02)Cartographer源码无死角解析-(03) 新数据运行与地图保存、加载地图启动仅定位模式
  • (11)工业界推荐系统-小红书推荐场景及内部实践【粗排三塔模型】
  • (3)Dubbo启动时qos-server can not bind localhost22222错误解决
  • (c语言+数据结构链表)项目:贪吃蛇
  • (办公)springboot配置aop处理请求.
  • (附源码)springboot 个人网页的网站 毕业设计031623
  • (十)c52学习之旅-定时器实验
  • (十)T检验-第一部分
  • (四)软件性能测试
  • (转)IOS中获取各种文件的目录路径的方法
  • (转)母版页和相对路径
  • .dat文件写入byte类型数组_用Python从Abaqus导出txt、dat数据
  • .NET 4 并行(多核)“.NET研究”编程系列之二 从Task开始
  • .NET 8 中引入新的 IHostedLifecycleService 接口 实现定时任务
  • .Net Core 生成管理员权限的应用程序
  • .NET Core中的时区转换问题
  • .NET WPF 抖动动画
  • .NET/ASP.NETMVC 深入剖析 Model元数据、HtmlHelper、自定义模板、模板的装饰者模式(二)...
  • .NET/C# 将一个命令行参数字符串转换为命令行参数数组 args
  • :class的用法及应用
  • @ 代码随想录算法训练营第8周(C语言)|Day57(动态规划)
  • @hook扩展分析
  • [023-2].第2节:SpringBoot中接收参数相关注解
  • [2]十道算法题【Java实现】