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

Cybersecurity & Ethical Hacking Terminology: 100+ Essential Terms Explained

Cybersecurity has its own vocabulary. When you begin studying cybersecurity, you will quickly encounter terms such as malware, phishing, vulnerability, exploit, authentication, authorization, firewall, zero-day, ransomware, social engineering, penetration testing, and threat actor . At first, these terms can seem confusing. Some are closely related, while others describe completely different concepts. This glossary provides a beginner-friendly explanation of the most important cybersecurity and ethical-hacking terminology. The goal is not to memorize every word. Instead, use this guide as a reference whenever you encounter an unfamiliar security term. A — Cybersecurity Terms Access Control Access control determines who or what is allowed to access a resource and what they are permitted to do with it . It is commonly implemented using permissions, roles, policies, and authentication mechanisms. Active Directory Active Directory is Microsoft's directory and identity-management techno...

Mandatory Skills Every Tech Professional Should Have on Their Resume

A technology resume is more than a collection of programming languages and frameworks. Recruiters want to understand what you can actually build, how you solve problems, and whether you can work with the tools used in modern software development. If you're preparing a resume for a software developer, web developer, DevOps engineer, data professional, or other technology role, these are the major skill categories you should consider including. 1. Programming Languages Start with the programming languages you actually know. Depending on your career path, these might include: JavaScript TypeScript Python Java C++ C# Go PHP Don't add every language you've ever watched a tutorial about. If an interviewer asks you to solve a problem using a language listed on your resume, you should be comfortable using it. 2. Frameworks and Libraries Framework knowledge is important because modern software development rarely involves building everything from scratch. Examples include: React Next...

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...