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.
Try the API directly: https://karenwky-diabetes-predictor.hf.space/docs
diabetes-predictor.mp4
- 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
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
-
Clone and navigate to the project:
cd /Users/karen/Documents/aie-journey/study/deployment/diabetes-predictor
-
Install dependencies:
pip install -r requirements.txt
-
Run the API server:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
-
Access the API:
- API: http://localhost:8000
- Interactive docs: http://localhost:8000/docs
- Alternative docs: http://localhost:8000/redoc
-
Build the Docker image:
docker build -t diabetes-predictor .
-
Run the container:
docker run -p 8000:8000 diabetes-predictor
Check if the API is running:
curl http://localhost:8000/
Response:
{
"status": "healthy",
"model": "diabetes_progression_v1"
}
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"
}
The API expects normalized physiological features:
age
: Patient agesex
: Patient sexbmi
: Body mass indexbp
: Average blood pressures1
: Serum measurement 1s2
: Serum measurement 2s3
: Serum measurement 3s4
: Serum measurement 4s5
: Serum measurement 5s6
: Serum measurement 6
- < 100: Below average progression
- 100-150: Average progression
- > 150: Above average progression
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']}")
- 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
- Step-by-Step Guide to Deploying Machine Learning Models with FastAPI and Docker - MachineLearningMastery.com
- Docker Spaces | Hugging Face Hub Documentation
- Deploying Your FastAPI Applications on Huggingface Via Docker
- Say Goodbye to Print(): Use Logging Module for Effective Debugging - KDnuggets
This project is licensed under the MIT License - see the LICENSE file for details.