A Logistic Regression classifier trained on the UCI Cleveland Heart Disease Dataset that predicts cardiovascular disease risk from 13 routine clinical measurements.
This model takes 13 clinical features collected during a routine patient checkup and predicts whether that patient has heart disease (1) or not (0). It was trained as part of an Applied Machine Learning course final project and deployed as a full-stack web application.
Three models were trained and compared — Logistic Regression, Random Forest, and XGBoost. Logistic Regression achieved the highest cross-validated accuracy and was selected as the deployed model. Random Forest achieved the best AUC score.
Model Performance
Model
CV Accuracy
AUC Score
Logistic Regression
80.5%
0.84
Random Forest (tuned)
75.4%
0.86
XGBoost
68.7%
0.78
Evaluated using 5-fold cross-validation on 297 patients
Logistic Regression outperformed more complex models — consistent with literature showing simpler models generalize better on small datasets (n < 300)
Hyperparameter tuning performed on Random Forest using GridSearchCV across 36 parameter combinations
Citation: Janosi, A., Steinbrunn, W., Pfisterer, M., & Detrano, R. (1989). Heart Disease [Dataset]. UCI Machine Learning Repository. https://doi.org/10.24432/C52P4X
Property
Value
Patients
297
Features
13 clinical inputs
Target
Binary (0 = No Disease, 1 = Disease)
Class balance
54% negative · 46% positive
Missing values
None
Input Features
Feature
Description
Type
age
Patient age in years
Numeric
sex
Biological sex (0=Female, 1=Male)
Binary
cp
Chest pain type (0–3)
Categorical
trestbps
Resting blood pressure (mmHg)
Numeric
chol
Serum cholesterol (mg/dl)
Numeric
fbs
Fasting blood sugar > 120 mg/dl (0/1)
Binary
restecg
Resting ECG results (0–2)
Categorical
thalach
Maximum heart rate achieved
Numeric
exang
Exercise induced angina (0/1)
Binary
oldpeak
ST depression induced by exercise
Numeric
slope
Slope of peak exercise ST segment (0–2)
Categorical
ca
Number of major vessels colored (0–3)
Numeric
thal
Thalassemia type (0–3)
Categorical
Top predictors identified by Random Forest feature importance:
thalach — max heart rate (higher = lower risk)
thal — thalassemia type
ca — number of major vessels
cp — chest pain type
How to Use
python
1import joblib
2import numpy as np
34# Load model and scaler5model = joblib.load('heart_disease_model.pkl')6scaler = joblib.load('scaler.pkl')78# Input features in exact order:9# age, sex, cp, trestbps, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal10patient = np.array([[63,1,3,145,233,1,2,150,0,2.3,2,0,2]])1112# Scale and predict13scaled = scaler.transform(patient)14prediction = model.predict(scaled)[0]15confidence = model.predict_proba(scaled)[0].max()1617print(f"Prediction: {'High Risk'if prediction ==1else'Low Risk'}")18print(f"Confidence: {confidence*100:.1f}%")
Files
File
Description
heart_disease_model.pkl
Trained Logistic Regression model
scaler.pkl
Fitted StandardScaler for feature normalization
Limitations
Small dataset (297 patients) from a single institution — Cleveland Clinic
Model has not been clinically validated
No imaging, genetic, or longitudinal data included
For educational purposes only — not intended for real medical diagnosis
If you use this model, please cite the original dataset:
Janosi, A., Steinbrunn, W., Pfisterer, M., & Detrano, R. (1989).
Heart Disease [Dataset]. UCI Machine Learning Repository.
https://doi.org/10.24432/C52P4X
Built as a final project for Applied Machine Learning / Deep Learning — Dr. Kargar.For educational purposes only. Not a substitute for professional medical advice.