CoolFace
Apppublic

MotavalD/Stroke_Prediction

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
App README

๐Ÿซ€ Stroke Risk Prediction API

A machine learning API that predicts stroke risk from patient health data. Built with FastAPI, Scikit-learn, and Docker โ€” deployed as a production-ready REST endpoint.


What it does

Takes patient health indicators as input and returns a binary stroke risk prediction (0 = low risk, 1 = high risk). The model was trained on a healthcare stroke dataset with preprocessing, feature engineering, and class-imbalance handling.


Tech stack

LayerTool
API frameworkFastAPI
ML modelScikit-learn (best-performing classifier)
PreprocessingPandas, NumPy, StandardScaler
SerializationPickle
DeploymentDocker

API usage

Endpoint: POST /predict

Request body (JSON):

json
{
  "age": 67.0,
  "hypertension": 0,
  "heart_disease": 1,
  "avg_glucose_level": 228.69,
  "bmi": 36.6,
  "gender_Male": 1,
  "gender_Other": 0,
  "ever_married_Yes": 1,
  "work_type_Never_worked": 0,
  "work_type_Private": 1,
  "work_type_Self_employed": 0,
  "work_type_children": 0,
  "Residence_type_Urban": 0,
  "smoking_status_formerly_smoked": 1,
  "smoking_status_never_smoked": 0,
  "smoking_status_smokes": 0
}

Response:

json
{
  "prediction": 1
}

1 = high stroke risk, 0 = low stroke risk


Input features explained

FeatureDescription
agePatient age in years
hypertension1 if patient has hypertension
heart_disease1 if patient has heart disease
avg_glucose_levelAverage blood glucose level (mg/dL)
bmiBody mass index
gender_Male / gender_OtherOne-hot encoded gender
ever_married_Yes1 if ever married
work_type_*One-hot encoded work category
Residence_type_Urban1 if urban resident
smoking_status_*One-hot encoded smoking history

Run locally

bash
# Clone the space
git clone https://huggingface.co/spaces/MotavalD/Stroke_Prediction

# Build and run with Docker
docker build -t stroke-api .
docker run -p 7860:7860 stroke-api

# Test the API
curl -X POST http://localhost:7860/predict \
  -H "Content-Type: application/json" \
  -d '{"age": 67, "hypertension": 0, "heart_disease": 1, ...}'

GitHub

Full source code and model training notebook available at: ๐Ÿ‘‰ github.com/dhruv-motaval


Built by [Dhruv Motaval](https://www.linkedin.com/in/dhruv-motaval/) โ€” B.Tech AI, Parul University