Skip to content
 
 

Latest commit

 

History

81 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CHD Classifier API — 10-Year Coronary Heart Disease Risk Prediction

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.

🙋 My contribution — David Hidalgo Fàbregas

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.

Overview

  • 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

Pipeline

  1. Data cleaning & imputation — missing values handled for glucose, BPMeds, BMI, heart rate, and smoking-related fields
  2. Exploratory data analysis & normalization
  3. Feature selection — correlation analysis within physiologically related variable groups (blood pressure, metabolic, lifestyle)
  4. Modeling — Logistic Regression vs. Random Forest, compared on ROC-AUC, recall, and accuracy
  5. Validation — stratified 80/20 train-test split, 5-fold stratified cross-validation, class weighting to address class imbalance
  6. API design & deployment — FastAPI service exposing the trained model, containerized with Docker

API usage

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.

Tech stack

Python · pandas · scikit-learn · FastAPI · Docker · Render (deployment) · Git/GitHub

Repository structure

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

Run locally

pip install -r requirements.txt
uvicorn api.main:app --host 0.0.0.0 --port 8000

Or with Docker:

docker build -t chd-classifier-api .
docker run -p 8000:8000 chd-classifier-api

The API will be available at http://localhost:8000.

About

Random Forest pipeline classifying 10-year coronary heart disease risk (4,000+ patient cohort), deployed as a FastAPI service in Docker. Team project — my role: API design & deployment.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages