A full-stack web application that predicts health risk (High/Low) based on lifestyle and physical metrics using a trained Random Forest Classifier (88.3% accuracy).
health_risk_app/
├── app.py # Flask server (API + static file serving)
├── predict.py # Prediction logic (loads saved model)
├── train_model.py # Model training script (run once)
├── requirements.txt # Python dependencies
├── Procfile # For Heroku/Render deployment
├── Lifestyle_and_Health_Risk_Prediction_Synthetic_Dataset.csv
├── models/ # Saved model artifacts (generated by train_model.py)
│ ├── rf_model.pkl
│ ├── scaler.pkl
│ ├── le_target.pkl
│ ├── professions.pkl
│ └── features.pkl
└── static/
└── index.html # Single-page frontend (Landing + Form + Results)
- Landing page — model stats, feature highlights
- Assessment form — all 11 input features with smart BMI auto-calculation
- Results page — risk score, gauge chart, factor breakdown, personalised suggestions
- No login/signup required • No data stored
# 1. Install dependencies
pip install -r requirements.txt
# 2. Train the model (only needed once, or if you change the dataset)
python train_model.py
# 3. Run the server
python app.py
# → Open http://localhost:5000- Push this folder to a GitHub repo
- Go to https://render.com → New Web Service
- Connect your repo
- Set Build Command:
pip install -r requirements.txt && python train_model.py - Set Start Command:
gunicorn app:app - Deploy!
# Install Railway CLI, then:
railway login
railway init
railway upheroku login
heroku create your-app-name
git push heroku main
heroku run python train_model.py| Model | Accuracy |
|---|---|
| Random Forest (100 trees, max_depth=5) | 88.3% |
| Decision Tree | ~82% |
| Naive Bayes | ~78% |
Input features: age, weight, height, BMI, sleep, exercise, sugar intake, smoking, alcohol, marital status, profession
Target: High Risk / Low Risk