Machine learning API — 2026
MomCare AI
The backend for MomCare AI: a FastAPI service that takes a patient's vitals, lifestyle and background details and predicts maternal health risk as low, mid or high, with a confidence score for each class.
- 17input features
- 3risk classes
- 200trees in the forest
- ~1,000records in the dataset
The goal
Turn a set of everyday health and lifestyle measurements into an early risk signal that a maternal-care app can show.
What I built
The model
A Random Forest classifier with 200 trees and balanced class weights, trained on a dataset of about 1,000 records using a stratified 80/20 train and test split.
17 input features
Vitals (age, blood pressure, blood sugar, body temperature, heart rate), lifestyle (sleep, physical activity, stress), nutrition (diet quality and adherence, hemoglobin, iron and folic supplements) and background (education, income, urban or rural).
Preprocessing
Categorical answers such as income level or diet adherence are mapped to ordered numbers, and the three risk labels are encoded for training and decoded back for the response.
Prediction API
A FastAPI endpoint, POST /predict, validates every field with typed models and returns clear error messages for bad input. It responds with the predicted risk level and a confidence percentage for each class, and allows cross-origin requests so a frontend can call it.
Model packaging
The trained model and label encoder are saved with joblib and loaded once when the service starts.
The stack
- Machine learning
- Pythonscikit-learn (Random Forest)pandasNumPyjoblib
- API
- FastAPIPydanticGunicorn
The outcome
- A working prediction API with a clearly defined request and response.
- Model and encoder ship with the backend, ready for an app to call.
A prototype for demonstration. It is not a medical device and its predictions are not medical advice.
Don't take my word
Anyone can write “it works”. This checks the code for real, right now, from a server, and shows exactly what it finds.
BUILDING SOMETHING SIMILAR?