Skip to content

karenwky/diabetes-predictor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🩺 Diabetes Progression Predictor

A machine learning API that predicts diabetes progression scores based on physiological features. Built with FastAPI and scikit-learn, this service provides real-time predictions through a RESTful API interface.

🌐 Live Demo

Try the API directly: https://karenwky-diabetes-predictor.hf.space/docs

πŸ“Ή Preview

diabetes-predictor.mp4

πŸ› οΈ Technologies Used

  • FastAPI - Modern, fast web framework for building APIs
  • scikit-learn - Machine learning library for model training and prediction
  • Pydantic - Data validation and settings management
  • NumPy - Numerical computing library
  • Uvicorn - ASGI server for running the FastAPI application
  • Docker - Containerization for easy deployment
  • Python 3.13 - Programming language

πŸ“ Project Structure

diabetes-predictor/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── main.py              # FastAPI application and endpoints
β”œβ”€β”€ models/
β”‚   └── diabetes_model.pkl   # Trained machine learning model
β”œβ”€β”€ requirements.txt         # Python dependencies
β”œβ”€β”€ train_model.py           # Model training script
β”œβ”€β”€ train_model.ipynb        # Jupyter notebook for model development
β”œβ”€β”€ Dockerfile               # Container configuration
β”œβ”€β”€ app.log                  # Model training log
└── image_info.txt           # Docker images info

πŸš€ Getting Started

πŸ’» Local Development

  1. Clone and navigate to the project:

    cd /Users/karen/Documents/aie-journey/study/deployment/diabetes-predictor
  2. Install dependencies:

    pip install -r requirements.txt
  3. Run the API server:

    uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
  4. Access the API:

🐳 Docker Deployment

  1. Build the Docker image:

    docker build -t diabetes-predictor .
  2. Run the container:

    docker run -p 8000:8000 diabetes-predictor

πŸ“‹ API Usage

πŸ” Health Check

Check if the API is running:

curl http://localhost:8000/

Response:

{
  "status": "healthy",
  "model": "diabetes_progression_v1"
}

🎯 Make Predictions

Send patient data to get diabetes progression predictions:

curl -X POST "http://localhost:8000/predict" \
     -H "Content-Type: application/json" \
     -d '{
       "age": 0.05,
       "sex": 0.05,
       "bmi": 0.06,
       "bp": 0.02,
       "s1": -0.04,
       "s2": -0.04,
       "s3": -0.02,
       "s4": -0.01,
       "s5": 0.01,
       "s6": 0.02
     }'

Response:

{
  "predicted_progression_score": 213.34,
  "interpretation": "Above average progression"
}

πŸ“Š Input Parameters

The API expects normalized physiological features:

  • age: Patient age
  • sex: Patient sex
  • bmi: Body mass index
  • bp: Average blood pressure
  • s1: Serum measurement 1
  • s2: Serum measurement 2
  • s3: Serum measurement 3
  • s4: Serum measurement 4
  • s5: Serum measurement 5
  • s6: Serum measurement 6

πŸ“ˆ Interpretation Guide

  • < 100: Below average progression
  • 100-150: Average progression
  • > 150: Above average progression

πŸ§ͺ Example Usage with Python

import requests

# API endpoint
url = "http://localhost:8000/predict"

# Patient data
patient_data = {
    "age": 0.05,
    "sex": 0.05,
    "bmi": 0.06,
    "bp": 0.02,
    "s1": -0.04,
    "s2": -0.04,
    "s3": -0.02,
    "s4": -0.01,
    "s5": 0.01,
    "s6": 0.02
}

# Make prediction
response = requests.post(url, json=patient_data)
result = response.json()

print(f"Predicted Score: {result['predicted_progression_score']}")
print(f"Interpretation: {result['interpretation']}")

πŸ“ Notes

  • All input features should be normalized as per the diabetes dataset standard
  • The model returns a continuous progression score
  • Higher scores indicate greater diabetes progression
  • The API includes automatic data validation and error handling

πŸ™ Acknowledgments

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Releases

No releases published

Packages

No packages published

Languages