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)
Predict whether a patient is at risk of heart disease based on 10 clinical and lifestyle features, enabling early intervention and preventive care.
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
| 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 |
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 | 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 |
- π¬ 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
pandas # Data manipulation
numpy # Numerical operations
matplotlib # Custom visualizations
seaborn # Statistical plots
scikit-learn # ML models, metrics, preprocessing# 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.pyfrom 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.000Eng. Heba | Data Analyst & ML Engineer
- π GitHub: @eng-heba-tech
- π§ eng.heba.tech@gmail.com
- π Egypt
β If you find this project useful, please give it a star!

