A full-stack web application for mental health screening based on the DASS-42 (Depression Anxiety Stress Scales) questionnaire. This project demonstrates production-ready ML deployment with proper evaluation metrics, ethical considerations, and modern web technologies.
โ ๏ธ Important Disclaimer: This tool is for educational and informational purposes only. It is NOT a medical diagnosis. If you are experiencing mental health concerns, please consult a qualified mental health professional.
Mental health disorders affect approximately 1 in 4 people globally, yet many cases remain undiagnosed due to stigma, lack of awareness, or limited access to professional evaluation. This project aims to provide an accessible screening tool that can help individuals become aware of potential mental health concerns-not to replace professional diagnosis, but to encourage those who may benefit from professional help to seek it.
Source: OpenPsychometrics DASS Dataset (also available on Kaggle)
| Attribute | Value |
|---|---|
| Samples | 39,775 |
| Features | 42 questions (30 selected via RFE) |
| Collection Period | 2017-2019 |
| Response Scale | 1-4 (frequency of symptoms) |
| Target Classes | 4 (None, Mild, Moderate, Severe) |
The DASS-42 is a validated psychological instrument measuring three related negative emotional states:
- Depression: Dysphoria, hopelessness, devaluation of life, self-deprecation, lack of interest
- Anxiety: Autonomic arousal, skeletal muscle effects, situational anxiety, subjective experience
- Stress: Difficulty relaxing, nervous arousal, easily upset/agitated, irritability
Used Recursive Feature Elimination (RFE) with Random Forest to select the 30 most predictive questions from the original 42, ensuring a balance between model performance and questionnaire length.
- StandardScaler applied to normalize feature distributions
- Median imputation for missing values
- Quartile-based severity classification
| Model | Accuracy | F1-Score | ROC-AUC |
|---|---|---|---|
| Logistic Regression โ | 92.0% | 0.920 | 0.992 |
| SVM (RBF kernel) | 91.9% | 0.919 | 0.992 |
| Random Forest | 89.4% | 0.894 | 0.986 |
| Gradient Boosting | 89.2% | 0.893 | 0.987 |
โ Selected as best model based on weighted F1-score
- Stratified Train/Test Split (80/20) to maintain class distribution
- 5-Fold Cross-Validation for robust performance estimation
- Multiple Metrics (see below) to avoid accuracy-only evaluation
In mental health screening, class imbalance and cost asymmetry make accuracy a misleading metric:
| Issue | Impact |
|---|---|
| Class Imbalance | Most samples are "None" or "Mild" - a model predicting only these classes could achieve high accuracy while missing severe cases |
| False Negatives are Costly | Missing a severe case (predicting "None" when actual is "Severe") could delay critical intervention |
| False Positives Cause Anxiety | Over-predicting severity could cause unnecessary worry |
This is why we report:
- Precision: Of those predicted as a class, how many actually are?
- Recall: Of actual cases, how many did we correctly identify?
- F1-Score: Harmonic mean balancing precision and recall
- ROC-AUC: Model's ability to distinguish between classes
- False Reassurance: Predicting "None" for someone who is struggling could delay help-seeking
- Stigmatization: Predicting "Severe" could cause distress or be misused
- Cultural Bias: DASS was developed in Western contexts; responses may vary cross-culturally
- Clear Disclaimers: Prominent warnings that this is not a diagnosis
- Probability Display: Showing confidence prevents over-reliance on single prediction
- Actionable Recommendations: Encouraging professional consultation regardless of result
- No Data Storage: We do not store individual responses
- A replacement for professional mental health evaluation
- Suitable for clinical decision-making
- Validated for crisis situations (please contact emergency services if in crisis)
โโโโโโโโโโโโโโโโโโโ HTTP/JSON โโโโโโโโโโโโโโโโโโโ
โ โ โโโโโโโโโโโโโโโถ โ โ
โ Next.js โ โ FastAPI โ
โ Frontend โ โโโโโโโโโโโโโโโ โ Backend โ
โ (Vercel) โ Prediction โ (HF Space) โ
โ โ โ โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโ
โ Trained ML โ
โ Model โ
โ (joblib) โ
โโโโโโโโโโโโโโโโโโโ
- Python 3.10+
- Node.js 18+
- npm or yarn
We recommend using Google Colab for training to leverage free GPU resources:
- Open
ml/train_colab.ipynbin Google Colab - Run all cells to:
- Download the DASS dataset from Kaggle
- Train and compare 4 classifiers (Logistic Regression, Random Forest, SVM, Gradient Boosting)
- Apply StandardScaler for feature normalization
- Generate evaluation metrics and confusion matrices
- Save the best model to your Drive or download directly
- Copy these files to
backend/models/:psychiatric_model.joblib(trained model)scaler.joblib(fitted StandardScaler)feature_names.json(feature configuration)
Current Best Model: Logistic Regression with 92.0% accuracy and 99.2% ROC-AUC
cd backend
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000API docs will be available at http://localhost:8000/docs
cd frontend
npm install
npm run devOpen http://localhost:3000 in your browser.
.
โโโ backend/ # FastAPI backend
โ โโโ app/
โ โ โโโ main.py # API endpoints
โ โ โโโ schemas.py # Pydantic models
โ โ โโโ model.py # ML model loading
โ โโโ models/ # Saved ML models
โ โโโ Dockerfile
โ โโโ requirements.txt
โโโ frontend/ # Next.js frontend
โ โโโ app/
โ โ โโโ page.tsx # Questionnaire UI
โ โโโ package.json
โโโ ml/ # ML training
โ โโโ train.py # Training script
โ โโโ config.py # Configuration
โ โโโ outputs/ # Training artifacts
โโโ data/ # Dataset documentation
โโโ README.md
- Create a new Space on Hugging Face
- Select Docker as the Space SDK
- Upload the contents of the
backenddirectory to the Space - The Space will build automatically using the provided Dockerfile
- Note the Space URL (e.g.,
https://your-username-space-name.hf.space) for frontend configuration
- Import project to Vercel
- Set root directory to
frontend - Add environment variable:
NEXT_PUBLIC_API_URL=https://your-backend-url.run.app - Deploy
- Add longitudinal tracking (with proper consent and security)
- Implement SHAP values for prediction explanations
- Add multi-language support
- Create progressive web app (PWA) for offline access
- Conduct formal validation study
- Add comparison with other validated screening tools
- Lovibond, S.H. & Lovibond, P.F. (1995). Manual for the Depression Anxiety Stress Scales. Sydney: Psychology Foundation.
- OpenPsychometrics DASS Dataset
- DASS Official Website
This project is for educational purposes. The DASS questionnaire is in the public domain.