End-to-end machine learning pipeline that predicts a patient's 10-year risk of coronary heart disease (CHD) from clinical and lifestyle risk factors, served as a REST API and containerized with Docker.
Built as the final project for Scientific Programming (MHEDAS — Master's in Health Data Science, URV), by a 7-person team.
I led the design and deployment of the API layer: endpoint design, request/response schema, error handling, and model-loading lifecycle in FastAPI. I also coordinated the technical review across the rest of the pipeline (data cleaning, feature engineering, model validation) built by the team.
Beyond the API, I structured the task breakdown and designed the overall pipeline and repository layout to support good collaborative practices: a clear branching workflow to avoid merge/version conflicts, and a folder structure that let team members work on different pipeline stages in parallel without blocking each other.
My GitHub profile · this repo is a fork of the original team repository, preserving full commit history and authorship.
- Cohort: 4,000+ patient clinical records
- Target: binary classification — 10-year CHD risk (yes/no)
- Features: clinical and lifestyle risk factors — sex, age, education, smoking status & intensity, blood pressure medication, prior stroke/hypertension, diabetes, total cholesterol, systolic/diastolic blood pressure, BMI, heart rate, glucose
- Final model: Random Forest, selected over Logistic Regression (test ROC-AUC ≈ 0.71), prioritizing recall on CHD-positive cases given the clinical cost of false negatives
- Data cleaning & imputation — missing values handled for glucose, BPMeds, BMI, heart rate, and smoking-related fields
- Exploratory data analysis & normalization
- Feature selection — correlation analysis within physiologically related variable groups (blood pressure, metabolic, lifestyle)
- Modeling — Logistic Regression vs. Random Forest, compared on ROC-AUC, recall, and accuracy
- Validation — stratified 80/20 train-test split, 5-fold stratified cross-validation, class weighting to address class imbalance
- API design & deployment — FastAPI service exposing the trained model, containerized with Docker
The /predict endpoint accepts patient data as JSON and returns a risk prediction:
curl -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{
"sex": "M", "age": 50, "education": 2.0,
"currentSmoker": "Yes", "cigsPerDay": 20.0, "BPMeds": 0.0,
"prevalentStroke": 0, "prevalentHyp": 0, "diabetes": 0,
"totChol": 250.0, "sysBP": 130.0, "diaBP": 80.0,
"BMI": 28.0, "heartRate": 75.0, "glucose": 85.0
}'{
"prediction": 1,
"risk_probability": "63.42%",
"diagnosis": "High Risk of Coronary Heart Disease"
}Interactive API docs (Swagger UI) are auto-generated by FastAPI at /docs once the service is running.
Python · pandas · scikit-learn · FastAPI · Docker · Render (deployment) · Git/GitHub
| Folder | Contents |
|---|---|
docs/ |
Project report and API demo video |
data/ |
Data at each pipeline stage (raw → cleaned → processed → aggregated) |
notebooks/ |
EDA, feature engineering, and model development, with documented decisions |
src/ |
Shared library functions used across notebooks and the API |
models/ |
Trained model artifact (best_model.joblib) used by the API |
api/ |
FastAPI service (main.py) and its test suite |
pip install -r requirements.txt
uvicorn api.main:app --host 0.0.0.0 --port 8000Or with Docker:
docker build -t chd-classifier-api .
docker run -p 8000:8000 chd-classifier-apiThe API will be available at http://localhost:8000.