Skip to content

Repository files navigation

Heart Failure Prediction

This repository contains the final project for the Data Science in Health FS25 course. The goal is to develop and evaluate clinical prediction models to estimate 30-day mortality in patients with heart failure.


Objective

Heart failure is a leading global health concern with high long-term mortality. This project aims to support early risk stratification by building transparent and reliable models using routinely available clinical and laboratory features.

We compare Logistic Regression and Random Forests to:

  • Predict patient mortality
  • Analyze model interpretability and sensitivity
  • Optimize clinical utility via threshold calibration

Methodology

  • Logistic Regression

    • Transparent & interpretable baseline
    • Final model with AUC of 0.913, sensitivity: 87.3%, specificity: 87.0%
    • Threshold optimized at 0.33 for false-negative reduction
  • Random Forest

    • Captures complex nonlinear relationships
    • Tuned via 5-fold cross-validation
    • Final AUC of 0.8999, sensitivity: 81.7%, specificity: 89.6%
    • Top features: ST_Slope, Oldpeak, ExerciseAngina

Key Findings

  • Logistic regression provides strong interpretability with high sensitivity.
  • Random Forest slightly increases specificity but is less transparent.
  • Threshold tuning using Youden’s Index was critical for clinical relevance.
  • The trade-off between interpretability and sensitivity is highlighted.

Repository Structure

File/Folder Description
Heart_Failure_Prediction.Rmd Main R Markdown report with code and results
_main.Rmd Bookdown/HTML entry point
Heart_Failure_Prediction.pdf Rendered version for non-technical readers
references.bib Bibliography file
README.md You are here
.gitignore Git exclusions (e.g. .Rhistory, .Rproj.user/)

Extensions & Bonus

As a bonus, the random forest model was evaluated and compared with logistic regression — showcasing potential trade-offs in explainability vs. performance. Further extensions could include:

  • Calibration curves
  • Cost-sensitive learning
  • Oversampling techniques (e.g. SMOTE)

Academic Context

This work was conducted as part of the ZHAW BSc Data Science course in 2025.


dataset

Heart Failure Prediction Dataset https://www.kaggle.com/datasets/fedesoriano/heart-failure-prediction/data

About Dataset

Context Cardiovascular diseases (CVDs) are the number 1 cause of death globally, taking an estimated 17.9 million lives each year, which accounts for 31% of all deaths worldwide. Four out of 5CVD deaths are due to heart attacks and strokes, and one-third of these deaths occur prematurely in people under 70 years of age. Heart failure is a common event caused by CVDs and this dataset contains 11 features that can be used to predict a possible heart disease.

People with cardiovascular disease or who are at high cardiovascular risk (due to the presence of one or more risk factors such as hypertension, diabetes, hyperlipidaemia or already established disease) need early detection and management wherein a machine learning model can be of great help.

Attribute Information
Age: age of the patient [years]
Sex: sex of the patient [M: Male, F: Female]
ChestPainType: chest pain type [TA: Typical Angina, ATA: Atypical Angina, NAP: Non-Anginal Pain, ASY: Asymptomatic]
RestingBP: resting blood pressure [mm Hg]
Cholesterol: serum cholesterol [mm/dl]
FastingBS: fasting blood sugar [1: if FastingBS > 120 mg/dl, 0: otherwise]
RestingECG: resting electrocardiogram results [Normal: Normal, ST: having ST-T wave abnormality (T wave inversions and/or ST elevation or depression of > 0.05 mV), LVH: showing probable or definite left ventricular hypertrophy by Estes' criteria] MaxHR: maximum heart rate achieved [Numeric value between 60 and 202]
ExerciseAngina: exercise-induced angina [Y: Yes, N: No]
Oldpeak: oldpeak = ST [Numeric value measured in depression]
ST_Slope: the slope of the peak exercise ST segment [Up: upsloping, Flat: flat, Down: downsloping]
HeartDisease: output class [1: heart disease, 0: Normal] \

Source
This dataset was created by combining different datasets already available independently but not combined before. In this dataset, 5 heart datasets are combined over 11 common features which makes it the largest heart disease dataset available so far for research purposes. The five datasets used for its curation are: \

Cleveland: 303 observations
Hungarian: 294 observations
Switzerland: 123 observations
Long Beach VA: 200 observations
Stalog (Heart) Data Set: 270 observations
Total: 1190 observations
Duplicated: 272 observations

Final dataset: 918 observations

Acknowledgements
Creators: \

Hungarian Institute of Cardiology. Budapest: Andras Janosi, M.D.
University Hospital, Zurich, Switzerland: William Steinbrunn, M.D.
University Hospital, Basel, Switzerland: Matthias Pfisterer, M.D.
V.A. Medical Center, Long Beach and Cleveland Clinic Foundation: Robert Detrano, M.D., Ph.D. \

Donor:
David W. Aha (aha '@' ics.uci.edu) (714) 856-8779 \

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages