Skip to content

Repository files navigation

πŸŽ“ Student Mental Health Early Warning System

AI-powered early intervention β€” identifying struggling students weeks before crisis hits

Python Streamlit Claude XGBoost SHAP License


The gap between when a student starts struggling and when the university notices averages 4–6 weeks.
This system closes that gap β€” detecting behavioral distress signals in real-time and surfacing them
to counselors with AI-generated explanations, intervention plans, and personalized outreach drafts.



✨ What This System Does

Without This System With This System
Counselors learn about struggling students after failed exams or withdrawals Counselors are alerted 3–5 weeks earlier via behavioral pattern detection
No prioritization β€” all students treated equally Students ranked by risk score; counselors focus limited time on highest-need cases
Counselors must manually dig through records before outreach AI generates a full case packet: risk profile β†’ intervention plan β†’ personalized draft message
Institutional knowledge buried in manuals Counselors ask questions in plain English; RAG system surfaces relevant guidance instantly
No historical view of how risk evolved Week-by-week risk trajectory shows exactly when and why a student started declining

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              OULAD Dataset  (32,593 students Β· 7 modules)        β”‚
β”‚   studentInfo Β· studentVle Β· studentAssessment Β· Registrations   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚  Feature Engineering
                         β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚   master_dataset    β”‚   ← Behavioral + academic features
              β”‚   (32,593 rows)     β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚  ML Training
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β–Ό              β–Ό               β–Ό
   Logistic       Random Forest     XGBoost β˜…
   Regression                     AUC 0.975
                         β”‚
                         β”‚  SHAP Explainability
                         β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚  scored_students    β”‚   ← Risk scores + tiers
              β”‚  student_explanationsβ”‚  ← Top-3 behavioral drivers
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β–Ό                   β–Ό                         β–Ό
 AI Agent          Multi-Agent              RAG Knowledge
 (Tool Use)        Workflow                 Base (TF-IDF)
 Counselor Chat    Risk→Interventions       Counseling Docs
                   β†’Outreach Draft
                         β”‚
                         β–Ό
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚    Streamlit Dashboard        β”‚
          β”‚  7 Tabs Β· Real-time Streaming β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Key Features

πŸ€– AI Counselor Chat Agent

Natural language interface powered by Claude Sonnet 4-6 with tool use. Counselors ask questions like:

"Show me the top 5 high-risk female students in module AAA"
"Why is student 30268 flagged? What should I do?"
"Which students in the 35-55 age group need immediate outreach?"

Claude dynamically calls structured data tools, retrieves live results, and responds with actionable, compassionate guidance.


🧠 3-Agent Case Analysis Pipeline

For any student, a sequential multi-agent workflow generates a complete case packet via streaming output:

Agent 1: Risk Analyst          β†’  Structured behavioral risk profile
         ↓ (feeds output)
Agent 2: Intervention Advisor  β†’  3 ranked interventions (48h / 1 week / 4 weeks)
         ↓ (feeds strategy)
Agent 3: Outreach Writer       β†’  Warm, human, non-algorithmic student message

Each agent has a specialized system context. Output streams in real-time so counselors see the analysis build live.


πŸ“Š Temporal Early Warning Analysis

Quantifies exactly how many weeks earlier a tiered alert system would catch each student:

Early Signal Threshold  ──────●─────────────────────────────────────
(risk > 0.50, 2wk run)        β”‚                                     
                              │◄─── 4-week intervention window ─────►│
Standard Alert Threshold ─────┼──────────────────────●──────────────
(risk β‰₯ 0.66)                 Wk 6                   Wk 10

Claude generates a publishable 3-paragraph research finding from the delay data in ACM/IEEE style.


πŸ“š RAG Knowledge Base

12 institutional counseling guidance documents (crisis protocol, trauma-informed care, referral pathways, and more) made searchable via TF-IDF retrieval + Claude grounded Q&A. Every answer is cited to its source document.


πŸ“… Smart Appointment Booking

Risk-aware scheduling with automatic urgency assignment:

Risk Score Urgency Counselor Guidance
β‰₯ 0.80 πŸ”΄ Immediate Contact within 24 hours
0.66–0.79 🟑 Soon Schedule within 48 hours
< 0.66 🟒 Routine Monitor and check-in

Every booking generates a confidential AI pre-meeting briefing tailored to the advisor type (Class Advisor / Therapist / Career Advisor / Professional Advisor).


πŸ“ˆ Model Performance

Model AUC-ROC Accuracy F1 Score
Logistic Regression 0.89 82% 0.77
Random Forest 0.96 88% 0.85
XGBoost β˜… 0.975 91% 0.88

⚠️ Read this before trusting the table above

These numbers are inflated by target leakage. Every behavioral feature is computed over the entire course, then used to predict an end-of-course label. For a student who withdrew in week 4, engagement_span and last_activity don't predict the withdrawal β€” they encode it. Sorting on last_activity alone, with no model at all, scores AUC 0.908.

Rebuilt with a hard time boundary (only data a counselor would have in week N):

Information available AUC PR-AUC % flagged @0.66 Precision Recall
Full course (the table above) 0.973 0.979 47.4% 0.948 0.851
First 60 days 0.876 0.905 37.8% 0.910 0.651
First 30 days ← the honest model 0.821 0.858 33.9% 0.880 0.565
First 14 days 0.750 0.782 30.6% 0.814 0.472

Reproduce with python code/leakage_check.py. The tradeoff between lead time and accuracy is the real result of this project; the 0.975 is not.

Top behavioral predictors (SHAP-ranked):

  1. engagement_span β€” How long the student stayed active in the course
  2. engagement_decline β€” Week-over-week engagement deterioration slope
  3. dropout_modules β€” Prior withdrawal history across modules
  4. mean_score β€” Average assessment score
  5. active_days β€” Consistency of VLE presence

Temporal findings: Adding a 0.50 amber threshold delivers 3–5 additional weeks of intervention opportunity for ~80% of high-risk students.


πŸ—‚οΈ Project Structure

Capstone_MentalHealth/
β”‚
β”œβ”€β”€ code/
β”‚   β”œβ”€β”€ dashboard.py          # Streamlit app β€” main entry point
β”‚   β”œβ”€β”€ ai_agent.py           # Claude tool-use counselor chat agent
β”‚   β”œβ”€β”€ multi_agent.py        # 3-agent streaming case analysis workflow
β”‚   β”œβ”€β”€ risk_monitor.py       # Weekly trajectory simulation + crossing alerts
β”‚   β”œβ”€β”€ temporal_analysis.py  # Intervention delay quantification
β”‚   β”œβ”€β”€ booking.py            # Appointment booking + AI briefings
β”‚   └── rag_kb.py             # TF-IDF retrieval + grounded knowledge Q&A
β”‚
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ scored_students.csv       # ML predictions + risk tiers (32,593 students)
β”‚   β”œβ”€β”€ student_explanations.csv  # SHAP top-3 behavioral drivers per student
β”‚   β”œβ”€β”€ shap_values.csv           # Full SHAP value matrix
β”‚   β”œβ”€β”€ master_dataset.csv        # Engineered feature matrix
β”‚   β”œβ”€β”€ [raw OULAD CSVs]          # studentInfo, studentAssessment, etc.
β”‚   └── kb/                       # 12 counseling guidance documents
β”‚
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ xgb_model.pkl         # Primary XGBoost model (AUC 0.975)
β”‚   β”œβ”€β”€ rf_model.pkl          # Random Forest model
β”‚   β”œβ”€β”€ lr_model.pkl          # Logistic Regression baseline
β”‚   └── scaler.pkl            # StandardScaler for feature normalization
β”‚
β”œβ”€β”€ plots/                    # 14 generated visualization outputs
β”‚   β”œβ”€β”€ plot1_outcomes_demographics.png
β”‚   β”œβ”€β”€ plot5_roc_pr_curves.png
β”‚   β”œβ”€β”€ plot10_shap_summary.png
β”‚   └── ...
β”‚
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ PROJECT_DOCUMENTATION.md  # Full technical documentation (18 sections)
└── Student_Mental_Health_EarlyWarningSystem.ipynb

⚑ Quick Start

1. Clone and Install

git clone https://github.com/uvnikhil/student-mental-health-ews.git
cd student-mental-health-ews
pip install -r requirements.txt

2. Set Your API Key

# Create .env file in project root
echo "ANTHROPIC_API_KEY=your_key_here" > .env

Get your API key at console.anthropic.com.

3. Download the OULAD Dataset

The raw VLE interaction log (studentVle.csv) is too large for GitHub (433MB). Download it from the Open University OULAD page and place it in data/.

4. Run the Notebook (First Time Only)

Open Student_Mental_Health_EarlyWarningSystem.ipynb and run all cells to:

  • Engineer features and build master_dataset.csv
  • Train and save all models
  • Generate SHAP explanations
  • Create all 14 visualization plots

5. Launch the Dashboard

streamlit run code/dashboard.py

Open http://localhost:8501 in your browser.


πŸ”¬ Dataset

OULAD β€” Open University Learning Analytics Dataset
Published by The Open University (UK) for academic research.

Attribute Value
Total student-module records 32,593
Modules (courses) 7 (AAA–GGG)
At-risk students ~4,100 (12.6%)
Behavioral features VLE clicks Β· active days Β· engagement span Β· decline slope
Academic features Assessment scores Β· submission rates Β· late submissions
Demographic features Gender Β· Age band Β· IMD deprivation band

Note: Demographic features are used for context display only β€” not as ML predictors β€” to prevent discriminatory risk scoring.


πŸ› οΈ Tech Stack

Layer Technology Why
ML Model XGBoost Best AUC; tree-based = exact SHAP support
Explainability SHAP TreeExplainer Exact Shapley values per student
LLM Claude Sonnet 4-6 Tool use + streaming; ideal speed/capability balance
AI Framework Anthropic Python SDK Native tool use, streaming, multi-turn conversation
Dashboard Streamlit Python-native; handles state, chat, plots with zero HTML
Charts Plotly + Matplotlib Interactive trajectories + static SHAP visualizations
Retrieval TF-IDF (scikit-learn) Deterministic, fast, no embedding API needed
Environment python-dotenv Keeps API keys out of source code

🧭 Dashboard Tabs

Tab What It Does
Overview Cohort metrics, demographic breakdown, filterable student table
AI Counselor Chat Multi-turn chat with Claude; tool call transparency panel
Multi-Agent Case 3-agent streaming workflow: risk β†’ interventions β†’ outreach
Risk Monitor Week-by-week trajectory playback with crossing alerts
Temporal Analysis Intervention delay quantification + Plotly chart + research narrative
Appointment Booking Risk-aware scheduling + AI pre-meeting briefings
Knowledge Base TF-IDF RAG over 12 counseling guidance documents

βš–οΈ Ethics and Design Principles

  • Counselor in the loop β€” The system advises; humans decide. No autonomous action is taken.
  • Behavioral signals only β€” Demographics are excluded from ML features. Risk is predicted from behavior, not identity.
  • No clinical diagnoses β€” All output uses behavioral language. Specialist referral is always recommended for clinical concerns.
  • Privacy-by-design β€” AI briefings for counselors never expose algorithmic language to students.
  • Explainability first β€” Every risk flag comes with a ranked explanation of why. Black-box alerts are not acceptable in a wellbeing context.

πŸ“„ Documentation

Full technical documentation covering all 18 phases of the project β€” from dataset selection and feature engineering to SHAP explainability, agent architecture, and ethical design β€” is available in PROJECT_DOCUMENTATION.md.


πŸ‘₯ Team

Name Role
Nikhil Kumar Reddy Lead Developer β€” ML pipeline, AI agents, dashboard
Nithin Sarva Contributor β€” Data analysis, model evaluation
Jyothika Priyanka Contributor β€” Research, documentation, evaluation

πŸ™Œ Acknowledgements

  • Dataset: OULAD β€” Kuzilek, J., Hlosta, M., & Zdrahal, Z. (2017). Open University Learning Analytics Dataset. Scientific Data, 4, 170171.
  • LLM: Anthropic Claude β€” Claude Sonnet 4-6
  • Explainability: SHAP β€” Lundberg & Lee (2017)

Built as a Capstone Project Β· 2026

Helping universities find struggling students before it's too late.

About

πŸŽ“ AI-powered early warning system detecting struggling university students weeks before crisis β€” XGBoost (AUC 0.975) + Claude Sonnet multi-agent + SHAP explainability + Streamlit dashboard

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages