Skip to main content

Mental Health Prediction Using Machine Learning: Building an Explainable AI Web Application

Machine learning is increasingly being explored for applications in healthcare and wellbeing. However, building an ML model for a sensitive domain such as mental health requires more than simply achieving a high accuracy score. I developed a Mental Health Prediction & Assessment System that combines machine learning, PHQ-9 screening, Explainable AI and a Flask-based web application. The project is available on GitHub: https://github.com/starJeet000/Mental-Health-Prediction-Using-Machine-Learning What Is the Project? The application is designed as an educational and preliminary screening system that evaluates mental-health-related information and produces a risk prediction. It combines an ML-based prediction system with a standardized PHQ-9 questionnaire. The purpose is not to replace mental-health professionals but to demonstrate how machine learning can be incorporated into a complete software application. Machine Learning Model Several classification algorithms were tr...

Mental Health Prediction Using Machine Learning: Building an Explainable AI Web Application

Machine learning is increasingly being explored for applications in healthcare and wellbeing. However, building an ML model for a sensitive domain such as mental health requires more than simply achieving a high accuracy score.

I developed a Mental Health Prediction & Assessment System that combines machine learning, PHQ-9 screening, Explainable AI and a Flask-based web application.

The project is available on GitHub:

https://github.com/starJeet000/Mental-Health-Prediction-Using-Machine-Learning

What Is the Project?

The application is designed as an educational and preliminary screening system that evaluates mental-health-related information and produces a risk prediction.

It combines an ML-based prediction system with a standardized PHQ-9 questionnaire.

The purpose is not to replace mental-health professionals but to demonstrate how machine learning can be incorporated into a complete software application.

Machine Learning Model

Several classification algorithms were trained and evaluated:

  • AdaBoost
  • Random Forest
  • XGBoost
  • Logistic Regression

After model evaluation and tuning, the AdaBoost classifier achieved approximately 86.9% accuracy and was selected as the final model.

The models were evaluated using metrics and visualizations including confusion matrices, ROC-AUC and precision-recall analysis.

PHQ-9 Screening

The project also integrates the Patient Health Questionnaire-9 (PHQ-9).

PHQ-9 provides a standardized score between 0 and 27 based on nine questions.

The application uses this screening information alongside the machine-learning prediction to create an additional safety-oriented layer.

Explainable AI Using SHAP

One of the most important features of the project is Explainable AI.

Machine-learning models can sometimes behave like black boxes. A prediction without an explanation can be difficult to interpret.

To address this, the project uses SHAP, which generates visual explanations showing the contribution of individual features to a prediction.

This makes it possible to investigate not only what the model predicted, but also which factors influenced the prediction.


🧠 An infographic showcasing a Mental Health Prediction system powered by Machine Learning, PHQ-9 screening, and Explainable AI.


Technology Stack

The project uses:

  • Python
  • Pandas
  • NumPy
  • Scikit-learn
  • XGBoost
  • SHAP
  • Flask
  • Gunicorn
  • HTML5
  • CSS3
  • Bootstrap
  • Jinja2
  • Docker
  • Render
  • GitHub Actions

Application Features

The application includes several features beyond the ML model:

  • Mental-health risk prediction
  • PHQ-9 screening
  • SHAP-based explanations
  • Interactive web interface
  • Counselling booking interface
  • Crisis assistance information
  • Docker deployment
  • Automated uptime monitoring

The repository contains the Flask backend, ML artifacts, training notebook, dataset, templates, static assets and Docker configuration.

Why Explainability Matters

In sensitive applications, simply returning:

"Prediction: High Risk"

isn't enough.

Users and developers should be able to understand the factors that influenced the model.

Explainable AI techniques such as SHAP can help developers inspect model behavior and identify potentially important features.

Lessons From the Project

This project demonstrated that an ML application involves much more than model training.

A complete system requires:

Data → Preprocessing → Model → Evaluation → Explainability → Backend → UI → Deployment

It also requires careful consideration of limitations and responsible communication.


🧠 An infographic showcasing a Mental Health Prediction system powered by Machine Learning, PHQ-9 screening, and Explainable AI.


Final Thoughts

The project was an opportunity to combine Machine Learning, Explainable AI, Flask and DevOps into a single application.

The most important takeaway is that when machine learning is applied to sensitive areas, responsibility and transparency should be considered alongside performance.

⚠️ Disclaimer: This project is for educational and preliminary screening purposes only. It is not a substitute for professional medical advice, diagnosis or treatment.

Project Repository

https://github.com/starJeet000/Mental-Health-Prediction-Using-Machine-Learning 

Comments

Popular posts from this blog

The Complete AI + Cybersecurity + MERN Developer Roadmap for 2026

Artificial intelligence, cybersecurity, and web development are three of the most interesting areas of modern technology. Each field provides valuable career opportunities on its own. But combining them can create an especially powerful technical skill set. This roadmap is designed for developers and students who want to learn MERN + cybersecurity + AI and eventually build real-world applications that combine all three. Why Learn AI + Cybersecurity + MERN? Consider a modern security application. A user opens a React dashboard. The application sends information to a Node.js backend. The backend stores data in MongoDB. Security rules analyze the data. An AI service helps classify or summarize the results. That single system requires knowledge of: Frontend development Backend development Databases APIs Security AI Deployment This is the intersection we are targeting. Phase 1: Learn Web Fundamentals Start with: HTML CSS JavaScript HTTP REST APIs Git GitHub Do not rush into advanced AI bef...

Gemini API + Node.js: Building Your First AI-Powered App

Artificial intelligence APIs make it possible for web developers to add AI capabilities without training a machine-learning model from scratch. A Node.js backend can communicate with an AI service, process the response, and provide the result to a React frontend. This architecture can be used for chatbots, document analysis, cybersecurity applications, content tools, and many other projects. Basic Architecture A simple AI-powered application can look like: React Frontend ↓ Node.js / Express ↓ AI API ↓ Node.js ↓ React The most important design principle is that private API credentials should remain on the server. 1. Create the Node.js Application Start with a Node.js backend and an Express API. The backend should contain separate responsibilities for: Routes Controllers AI service logic Validation Error handling Keeping these responsibilities separated makes the application easier to maintain. 2. Protect Environment Variables AI API credentials should not be hard...