Skip to content

eng-heba-tech/Heart-Disease-Prediction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯ Heart Disease Risk Prediction β€” Machine Learning

Python Scikit-Learn Pandas ML Status


πŸ“Œ Project Overview

A complete Machine Learning pipeline for predicting heart disease risk in patients using clinical and lifestyle data. The project covers the full data science workflow: data generation, EDA, preprocessing, model training, evaluation, and interpretation.

Three classification models are compared:

  • πŸ“Š Logistic Regression
  • 🌲 Random Forest ← Best Model (AUC = 1.000)
  • πŸš€ Gradient Boosting (AUC = 0.955)

🎯 Objective

Predict whether a patient is at risk of heart disease based on 10 clinical and lifestyle features, enabling early intervention and preventive care.


πŸ“Š Dashboard Preview

Exploratory Data Analysis

EDA Dashboard

ML Model Evaluation

ML Results


πŸ“ Project Structure

Heart-Disease-Prediction/
β”‚
β”œβ”€β”€ πŸ“„ healthcare_data.csv       # Patient dataset (2,000 records)
β”œβ”€β”€ 🐍 generate_data.py          # Synthetic data generator
β”œβ”€β”€ 🐍 ml_analysis.py            # EDA + ML training & evaluation
β”œβ”€β”€ πŸ“Š eda_dashboard.png         # Exploratory analysis charts
β”œβ”€β”€ πŸ“Š ml_results.png            # Model comparison & ROC curves
└── πŸ“– README.md

πŸ“¦ Dataset Description

Feature Type Description
Age Integer Patient age (20–80)
BMI Float Body Mass Index
Glucose Integer Blood glucose level (mg/dL)
Blood_Pressure Integer Systolic blood pressure
Cholesterol Integer Total cholesterol (mg/dL)
Smoking Binary 1 = Smoker, 0 = Non-smoker
Exercise_Level Ordinal 0=None, 1=Low, 2=Medium, 3=High
Family_History Binary 1 = Family history of heart disease
Stress_Level Integer Self-reported stress (1–10)
Sleep_Hours Float Average daily sleep (hours)
Disease Binary Target: 1 = Disease, 0 = Healthy

πŸ”¬ ML Pipeline

Raw Data
   β”‚
   β–Ό
Exploratory Data Analysis (EDA)
   β”‚  β”œβ”€ Distribution plots
   β”‚  β”œβ”€ Correlation heatmap
   β”‚  └─ Risk factor analysis
   β”‚
   β–Ό
Preprocessing
   β”‚  β”œβ”€ Handle class imbalance (oversampling)
   β”‚  └─ Feature scaling (StandardScaler)
   β”‚
   β–Ό
Model Training (3 models)
   β”‚  β”œβ”€ Logistic Regression
   β”‚  β”œβ”€ Random Forest (200 estimators)
   β”‚  └─ Gradient Boosting (200 estimators)
   β”‚
   β–Ό
Evaluation
   β”‚  β”œβ”€ ROC-AUC Score
   β”‚  β”œβ”€ Confusion Matrix
   β”‚  β”œβ”€ Precision / Recall / F1
   β”‚  └─ Feature Importance
   β”‚
   β–Ό
Best Model: Random Forest (AUC = 1.000)

πŸ“ˆ Model Performance

Model AUC Score Notes
Logistic Regression 0.612 Baseline linear model
Gradient Boosting 0.955 Strong ensemble model
Random Forest 1.000 βœ… Best β€” recommended for deployment

πŸ” Key Findings

  • 🚬 Smoking is the strongest risk factor for disease
  • πŸ‘¨β€πŸ‘©β€πŸ‘¦ Family History doubles disease probability
  • πŸƒ Regular exercise significantly reduces risk
  • 🍬 High glucose & BMI are correlated with disease
  • 😴 Poor sleep (< 5 hours) increases risk by ~40%
  • πŸ’ͺ Random Forest outperforms other models with perfect AUC on test set

πŸ› οΈ Technologies Used

pandas         # Data manipulation
numpy          # Numerical operations
matplotlib     # Custom visualizations
seaborn        # Statistical plots
scikit-learn   # ML models, metrics, preprocessing

▢️ How to Run

# 1. Clone the repository
git clone https://github.com/eng-heba-tech/Heart-Disease-Prediction
cd Heart-Disease-Prediction

# 2. Install dependencies
pip install pandas numpy matplotlib seaborn scikit-learn

# 3. Generate dataset
python generate_data.py

# 4. Run full analysis + ML
python ml_analysis.py

🧠 Sample Code β€” Model Training

from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42, stratify=y)

rf = RandomForestClassifier(n_estimators=200, random_state=42)
rf.fit(X_train, y_train)

auc = roc_auc_score(y_test, rf.predict_proba(X_test)[:,1])
print(f"Random Forest AUC: {auc:.3f}")  # Output: 1.000

πŸ‘©β€πŸ’» Author

Eng. Heba | Data Analyst & ML Engineer


⭐ If you find this project useful, please give it a star!

About

πŸ₯ ML pipeline to predict heart disease risk using 10 clinical features | Python β€’ Scikit-Learn β€’ Random Forest (AUC=1.0) β€’ EDA Dashboard

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages