An end-to-end machine-learning project on the Kaggle/UCI heart-disease dataset, built around real-world engineering practices: leakage prevention, clinical feature engineering, model comparison, and explainability.
302
Unique patients
0.886
Test ROC-AUC
84.8%
Recall (sensitivity)
5
Final features
Pipeline
From raw CSV to a model served in production, the project follows ten deliberate steps. Hover or tap any card to see what happens at each stage.
01
Raw data
Hover or tap to read →
Step 01
Kaggle/UCI heart dataset, deduplicated to 302 unique patients. Binary target: disease vs. no disease.
02
Exploratory analysis
Hover or tap to read →
Step 02
Explored every variable — distributions, relationship to the target, and outliers — before modeling.
03
Train / Val / Test split
Hover or tap to read →
Step 03
Split first, so preprocessing never sees the test data. The key guard against data leakage.
04
Preprocessing
Hover or tap to read →
Step 04
Impossible zeros → NaN, then median imputation fitted only on the training set and applied to the rest.
05
Feature engineering
Hover or tap to read →
Step 05
Two clinical proxies — ischemia_score and est_stroke_volume — capturing patterns beyond the raw columns.
06
Feature selection
Hover or tap to read →
Step 06
Correlation, multicollinearity, VIF and ablation trimmed the set to the 6 most useful features.
07
Model training
Hover or tap to read →
Step 07
Logistic Regression, Random Forest and XGBoost tuned with 5-fold stratified GridSearchCV on ROC-AUC.
08
Evaluation
Hover or tap to read →
Step 08
Compared on accuracy, ROC-AUC, recall, precision, F1 and the CV-to-test generalization gap.
09
SHAP explainability
Hover or tap to read →
Step 09
Explained predictions globally and per-patient, confirming the engineered features add real signal.
10
Final model — Random Forest
Hover or tap to read →
Step 10
Best ROC-AUC (0.886) with an acceptable gap. Serialized as .pkl for production inference.
FastAPI
POST /predict — serves the model
Next.js UI
Form → risk result
The data
The study uses the Kaggle/UCI heart-disease dataset, deduplicated to 302 unique patients. It is framed as binary classification (0 = no disease, 1 = disease).
Target distribution — near-balanced classes.
Class balance preserved across train / val / test (stratified).
Exploratory analysis
Before modeling, each variable was explored for distribution, relationship with the target, and outliers. Click any figure to enlarge.
Numeric features — distributions
age — distribution
chol — distribution
oldpeak — distribution
thalach — distribution
trestbps — distribution
Numeric features — relationship with target
age vs. target
chol vs. target
oldpeak vs. target
thalach vs. target
trestbps vs. target
Outlier detection
age — outlier strip plot
chol — outlier strip plot
oldpeak — outlier strip plot
thalach — outlier strip plot
trestbps — outlier strip plot
Exploratory analysis
Categorical features — distributions
cp — distribution
thal — distribution
ca — distribution
slope — distribution
sex — distribution
exang — distribution
restecg — distribution
fbs — distribution
Categorical features — by target
cp by target
thal by target
ca by target
slope by target
sex by target
exang by target
restecg by target
fbs by target
Exploratory analysis
Correlation with target
Feature correlation with the target.
Preprocessing
Engineered clinical features
ischemia_score
oldpeak + exang + (ca / 3)Combines multiple indicators of cardiac stress.
est_stroke_volume
(trestbps / thalach) × (age / 50)Approximates cardiovascular efficiency under stress.
Validated with correlation analysis, multicollinearity checks, VIF and ablation tests — both engineered features ranked among the top predictors.
Model evaluation
ROC curves on the held-out test set — all three models clearly beat the random baseline, with Random Forest achieving the highest AUC (0.886).
ROC curves — all three models on the held-out test set.
Random Forest was selected for the strongest ROC-AUC with an acceptable generalization gap (0.050).
Model
Accuracy
ROC-AUC
Recall
Precision
F1
CV Gap
Random Forest
Selected
80.33%
0.886
0.848
0.800
0.824
0.061
Logistic Regression
81.97%
0.882
0.818
0.844
0.831
0.061
XGBoost
78.69%
0.873
0.848
0.778
0.812
0.083
Model Explainability
The model correctly identified 26 of 33 patients with heart disease (recall 78.8%).
Pred. No Disease
Pred. Disease
Actual No Disease
21
True Negative
7
False Positive
Actual Disease
5
False Negative
28
True Positive
Model Explainability
Average absolute SHAP values showing which clinical variables have the greatest influence across all model predictions.
Displays how each feature contributes to increasing or decreasing the predicted cardiovascular risk across the entire dataset.
Explains how each clinical feature influences the prediction for a single patient, highlighting the factors that increase or decrease the estimated risk.
SHAP (SHapley Additive exPlanations) provides transparent explanations for machine learning predictions by quantifying how each clinical variable contributes to the estimated cardiovascular risk.
cp — Chest pain type — the strongest signal
29.7%
thal — Key diagnostic feature
24.5%
ca — Number of major vessels colored by fluoroscopy
22.8%
oldpeak — ST depression induced by exercise
17.3%
sex — Contributed to predictions
5.6%
Jhoselyn Pajuelo - Software Engineer
Explore the full code on GitHub or reach out directly.