🚀 Live Demo: Predict Your Mental Health Now
An end-to-end Machine Learning web application designed to evaluate mental health indicators, perform standardized clinical depression screenings (PHQ-9), and provide visual decision transparency using Explainable AI (SHAP).
- Machine Learning Risk Prediction: Utilizes an optimized AdaBoost Classifier trained on tech workplace survey data to predict mental health treatment likelihood.
- Clinical PHQ-9 Screening: Integrated 9-question Patient Health Questionnaire providing immediate severity scoring (0 to 27 scale) alongside AI predictions.
- Clinical Safety Override: System architecture ensures patient safety by prioritizing standardized clinical symptom thresholds (PHQ-9 >= 10) over demographic-based AI predictions when determining final risk outputs.
- Explainable AI (XAI): Implements SHAP (SHapley Additive exPlanations) to render dynamic Waterfall plots explaining feature contributions for each prediction.
- Interactive Counselling Booking: Seamless form interface allowing users to schedule sessions directly with mental health specialists.
- Crisis Assistance: Localized emergency contact info and 24/7 helplines embedded directly into result views.
- Containerized Deployment: Includes production-ready Docker support powered by Gunicorn.
- Zero Cold-Start Optimization: Integrated automated 14-minute cron pings via GitHub Actions and UptimeRobot to prevent cloud container spin-downs.
- Machine Learning & Data Science: Python 3.12, Scikit-Learn, Pandas, NumPy, XGBoost, SHAP
- Backend Framework: Flask, Gunicorn
- Frontend: HTML5, CSS3, Bootstrap 5, Jinja2
- DevOps & Tooling: Docker, VS Code, Render
Multiple classification algorithms were trained, tuned, and evaluated during exploratory data analysis:
- AdaBoost Classifier (Tuned): ~86.9% Accuracy (Selected Final Model)
- Random Forest Classifier
- XGBoost Classifier
- Logistic Regression
Model evaluation was validated using Confusion Matrices, ROC-AUC curves, and Precision-Recall metrics.
├── models/ # Serialized ML artifacts (.pkl)
│ ├── model.pkl # Trained AdaBoost Classifier
│ ├── ct.pkl # ColumnTransformer pipeline
│ └── le.pkl # LabelEncoder object
├── static/ # Static assets (CSS, JS, generated plots)
│ ├── css/
│ └── images/ # Dynamic SHAP plot storage
├── templates/ # HTML Jinja2 Templates
│ ├── index.html # Landing page & booking form
│ ├── form.html # Primary ML & PHQ-9 assessment form
│ ├── result.html # Dynamic prediction & XAI dashboard
│ └── booking_success.html # Appointment confirmation view
├── app.ipynb # Jupyter Notebook for Data Cleaning, EDA & Training
├── app.py # Flask Application Backend
├── Dockerfile # Production Containerization Specification
├── requirements.txt # Unpinned Python dependencies
├── changelog.md # Project version history
└── survey.csv # Kaggle OSMI Mental Health Dataset
-
Python 3.10+ installed
-
Git
- Clone the Repository:
git clone https://github.com/starJeet000/Mental-Health-Prediction-Using-Machine-Learning.git
cd Mental-Health-Prediction-Using-Machine-Learning- Create and Activate Virtual Environment:
#Windows (PowerShell)
python -m venv .venv
.venv\Scripts\Activate.ps1
#Linux / macOS
python3 -m venv .venv
source .venv/bin/activate- Install Dependencies:
pip install -r requirements.txt- Run the Flask Server:
python app.py- Access the Web App:
Open your browser and navigate to http://127.0.0.1:8000.
To build and run the application inside a Docker container:
### Build the Docker image
docker build -t mental-health-app .
### Run the container
docker run -p 8000:8000 mental-health-appNavigate to http://localhost:8000 in your browser.
This application is built for educational and preliminary screening purposes only. It is not a substitute for professional medical advice, diagnosis, or treatment.