Skip to main content
Machine Learning Case Study Scikit-Learn · XGBoost · SMOTE Educational Research (Non-Clinical)

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.

XGBoost Accuracy
84.00%

+11.94% over Logistic Regression

Class 1 Precision
0.89

Up from 0.73 in baseline model

SMOTE Resampling
6,202

3,101 Class 0 · 3,101 Class 1

Clean Cohort
3,658

Complete records × 15 features

End-to-End Engineering Workflow

STEP 01

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.

STEP 02

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.

STEP 03

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.

STEP 04

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.

Before SMOTE (3,658 rows) 84.8% vs. 15.2%
Class 0 (No CHD): 3,101 Class 1 (CHD Risk): 557
After SMOTE (6,202 rows) 50.0% vs. 50.0%
Class 0 (No CHD): 3,101 Class 1 (CHD Risk): 3,101

15 Clinical & Demographic Predictors

Target: TenYearCHD (0 / 1)

All 15 input variables standardized with StandardScaler prior to classification:

Demographics & Habits

age male education currentSmoker cigsPerDay

Medical History

BPMeds prevalentStroke prevalentHyp diabetes

Clinical Vitals & Labs

sysBP diaBP totChol BMI heartRate glucose

Model Benchmark: Logistic Regression vs. XGBoost

Evaluated on the 1,861-sample test split (933 Class 0 · 928 Class 1) in heartDisease.ipynb.

Baseline Linear Model

Logistic Regression

solver='liblinear'
Test Accuracy (n=1,861) 72.06%
10-Fold CV ROC-AUC 0.7813 (±0.019)

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

Primary Gradient-Boosted Model

XGBoost Classifier

+11.94% Accuracy Lift
Test Accuracy (n=1,861) 84.00%
5-Fold Cross-Validation Mean 83.00%

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

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

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)

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.