Heart Disease Risk Prediction with SMOTE & XGBoost
End-to-end tabular ML workflow on the Framingham Heart Study cohort (4,240 records) solving severe 85:15 class imbalance to boost 10-year CHD risk classification from 72.06% to 84.00% test accuracy.
+11.94% over Logistic Regression
Up from 0.73 in baseline model
3,101 Class 0 · 3,101 Class 1
Complete records × 15 features
End-to-End Engineering Workflow
Data Cleaning
4,240 → 3,658 Rows
Profiled 16 attributes, removed 582 incomplete rows across 7 columns (glucose, education, BPMeds, totChol, cigsPerDay, BMI, heartRate), verified 0 duplicates.
SMOTE Balancing
85:15 → 50:50 Split
Oversampled the 557 positive CHD cases to match the 3,101 negative cases using SMOTE(random_state=0), producing 6,202 balanced samples.
70/30 Split & Scaling
4,341 Train / 1,861 Test
Partitioned the balanced matrix into training and test subsets and normalized all 15 continuous and binary predictors with StandardScaler.
Boosted Classification
84.0% Peak Accuracy
Benchmarked Logistic Regression against XGBoost (max_depth=3, lr=0.05, n_estimators=100) and shipped a live CLI predictor (predict_chd).
Class Imbalance Resolution
Raw Framingham records were heavily skewed toward negative cases, causing baseline classifiers to miss positive CHD risk.
15 Clinical & Demographic Predictors
Target: TenYearCHD (0 / 1)All 15 input variables standardized with StandardScaler prior to classification:
Demographics & Habits
Medical History
Clinical Vitals & Labs
Model Benchmark: Logistic Regression vs. XGBoost
Evaluated on the 1,861-sample test split (933 Class 0 · 928 Class 1) in heartDisease.ipynb.
Logistic Regression
Class 0 (No CHD)
P: 0.72 · R: 0.73 · F1: 0.72
Class 1 (CHD Risk)
P: 0.73 · R: 0.71 · F1: 0.72
10-Fold CV Accuracy: 72.24% (±1.59%) · Log-Loss: -0.5616
XGBoost Classifier
Class 0 (No CHD)
P: 0.80 · R: 0.91 · F1: 0.85
Class 1 (CHD Risk)
P: 0.89 · R: 0.77 · F1: 0.82
learning_rate=0.05 · max_depth=3 · n_estimators=100 · eval_metric='logloss'
Production ML Review & Takeaways
Expand each card below for methodological considerations when moving from notebook exploration to production deployment:
1. Encapsulating SMOTE Inside Training Folds (Pipeline Leakage Guard)
Why SMOTE should run inside imblearn.pipeline.Pipeline after train_test_split
1. Encapsulating SMOTE Inside Training Folds (Pipeline Leakage Guard)
Why SMOTE should run inside imblearn.pipeline.Pipeline after train_test_split
In heartDisease.ipynb (Cell 63), SMOTE was fitted on the full (X, y) matrix prior to train_test_split (Cell 70). In production ML workflows, SMOTE must be encapsulated inside an imblearn.pipeline.Pipeline and applied strictly to the training split so the holdout test set retains its natural 15.23% prevalence without synthetic neighbor interpolation.
2. Persisting the Training StandardScaler for Live Inference
Reusing X_train mean and variance on test and single-patient CLI inputs
2. Persisting the Training StandardScaler for Live Inference
Reusing X_train mean and variance on test and single-patient CLI inputs
In Cell 83, a separate StandardScaler instance was fitted on X_test. For deterministic production inference—especially on single-patient requests—the exact mean and standard deviation fitted on X_train (sc_train.transform(X_test)) must be serialized and reused.
3. ColumnTransformer Imputation vs. Listwise Row Deletion
Preserving the 582 incomplete patient records (~13.7% of cohort)
3. ColumnTransformer Imputation vs. Listwise Row Deletion
Preserving the 582 incomplete patient records (~13.7% of cohort)
Dropping rows with missing values reduced the cohort from 4,240 to 3,658 records. Applying median/mode or iterative imputation inside a scikit-learn ColumnTransformer retains all 4,240 patient records during training.