I built an end-to-end Mental Health Prediction & Assessment System that combines machine learning, standardized screening, Explainable AI and a web application.
The objective was to explore what a more complete ML application looks like beyond simply training a model in a Jupyter Notebook.
🚀 What does the application do?
The system combines two major components:
1. Machine-learning-based risk prediction
2. PHQ-9-based clinical symptom screening
The results are presented through a web interface with additional explainability and support features.
🤖 Machine Learning Pipeline
I evaluated multiple classification algorithms:
- AdaBoost
- Random Forest
- XGBoost
- Logistic Regression
After tuning and evaluation, the AdaBoost classifier achieved approximately 86.9% accuracy and was selected as the final model.
Model evaluation included:
- Confusion matrices
- ROC-AUC curves
- Precision-Recall metrics
🩺 PHQ-9 Integration
One of the more interesting parts of the project is the integration of the Patient Health Questionnaire (PHQ-9).
The questionnaire contains nine questions and generates a score from 0 to 27.
The project uses this standardized screening layer alongside the machine-learning prediction rather than presenting the ML model as a medical diagnosis.
🔍 Explainable AI with SHAP
A prediction is much more useful when users can understand why a model reached it.
That's why I integrated SHAP (SHapley Additive exPlanations).
The application generates visual explanations showing how individual features contributed to a particular prediction.
This turns:
"The model predicted this."
into:
"These features contributed to the model's prediction."
That's an important distinction when building responsible ML applications.
🏗️ Architecture
The application uses:
User
↓
Web Interface
↓
Flask Application
↓
Data Processing
↓
ML Model
↓
Risk Prediction
↓
SHAP Explanation
↓
Result Dashboard
The project also contains serialized ML artifacts such as the trained model, preprocessing transformer and label encoder.
🛠️ Technology Stack
Machine Learning
- Python 3.12
- Scikit-learn
- XGBoost
- Pandas
- NumPy
- SHAP
Backend
- Flask
- Gunicorn
Frontend
- HTML5
- CSS3
- Bootstrap 5
- Jinja2
DevOps
- Docker
- Render
- GitHub Actions
🚀 Beyond Machine Learning
I also implemented additional application functionality:
- Interactive mental-health assessment
- SHAP visualization
- Counselling booking interface
- Crisis assistance information
- Docker-based deployment
- Automated uptime monitoring
The goal was to turn the ML experiment into an actual end-to-end web application.
📚 What I Learned
This project reinforced several important lessons:
1. Accuracy isn't everything
A model can have good accuracy and still be unsuitable for real-world use without considering context, limitations and safety.
2. Explainability matters
SHAP helped make the model's predictions easier to inspect.
3. Deployment changes everything
Moving from a notebook to Flask + Docker + Gunicorn introduced an entirely different set of engineering challenges.
4. Sensitive domains require extra caution
Mental-health applications should never present an ML prediction as a definitive medical diagnosis.
🔗 Source Code
The complete project is available on GitHub:
The repository also includes the Flask application, trained model artifacts, notebook, dataset, Docker configuration and requirements.
If you're learning Machine Learning, Flask, Explainable AI or ML deployment, I'd love to hear your feedback.
Top comments (0)