Mental Health Detection System
The Mental Health Detection System is an end-to-end machine learning application designed to assess a student’s mental health score based on their social media usage patterns, lifestyle habits, and academic behavior. The project combines data analytics, predictive modeling, and an interactive Streamlit dashboard to provide accurate and explainable mental health predictions.
Extra Trees
NLP
Feature Extraction
Deep Learning
91%
R2 score
0.91
CV score
0.27
MAE
8
Models
Extra Trees Regressor is an ensemble machine learning algorithm used for regression problems. It is similar to Random Forest but introduces more randomness when building decision trees. Instead of searching for the best split at each node, Extra Trees selects split points randomly, which helps reduce overfitting and often improves the model’s ability to generalize to unseen data.
How It Works
- Creates multiple decision trees using random subsets of the training data.
- At each split, it randomly selects a subset of features.
- Instead of finding the optimal split, it chooses a random split point.
- The predictions from all trees are averaged to produce the final prediction.
Mental Health Detection System
The Mental Health Detection System is an end-to-end machine learning application designed to assess a student’s mental health score based on their social media usage patterns, lifestyle habits, and academic behavior. The project combines data analytics, predictive modeling, and an interactive Streamlit dashboard to provide accurate and explainable mental health predictions.
Extra Trees
91%
R2 score
0.97
CV score
0.27
MAE
8
Models
Extra Trees Regressor is an ensemble machine learning algorithm used for regression problems. It is similar to Random Forest but introduces more randomness when building decision trees. Instead of searching for the best split at each node, Extra Trees selects split points randomly, which helps reduce overfitting and often improves the model’s ability to generalize to unseen data.
How It Works
- Creates multiple decision trees using random subsets of the training data.
- At each split, it randomly selects a subset of features.
- Instead of finding the optimal split, it chooses a random split point.
- The predictions from all trees are averaged to produce the final prediction.
Project Description
The Mental Health Detection System is a comprehensive machine learning application developed to predict a student’s Mental Health Score (0–10) using behavioral, lifestyle, academic, and social media usage data. The project demonstrates the complete machine learning lifecycle, including data preprocessing, exploratory data analysis (EDA), feature engineering, model training, hyperparameter tuning, evaluation, explainability, and deployment through an interactive Streamlit dashboard.
The system analyzes factors such as daily social media usage, sleep duration, stress level, physical activity, study hours, screen unlock frequency, academic performance, and demographic information to estimate an individual’s mental well-being score. By combining advanced machine learning techniques with interactive visualizations, the application enables users to explore the dataset, understand the model’s predictions, and gain insights into the factors that most influence mental health scores.
The project is designed for educational, research, and analytical purposes and demonstrates industry-standard practices for building an end-to-end machine learning application.
Problem Statement
Mental health challenges among students are becoming more prevalent due to increasing academic demands, excessive social media engagement, irregular sleep patterns, and unhealthy lifestyle habits. These factors often interact in complex ways, making it difficult to assess overall mental well-being using traditional approaches alone.
The challenge is to develop a data-driven system capable of analyzing multiple behavioral and lifestyle factors simultaneously to estimate a student’s mental health score accurately. Such a system should not only provide reliable predictions but also offer transparency into the factors influencing those predictions through explainable machine learning techniques.
This project addresses that challenge by building an interactive machine learning application that predicts mental health scores based on student-related data while providing meaningful visualizations, performance evaluation, and model interpretability.
Objectives
The primary objectives of this project are:
- Develop a machine learning model capable of predicting a student’s mental health score using behavioral and lifestyle features.
- Perform comprehensive data preprocessing, cleaning, and feature engineering to improve data quality and model performance.
- Conduct detailed exploratory data analysis (EDA) to identify patterns, relationships, and trends within the dataset.
- Compare multiple regression algorithms and select the best-performing model using objective evaluation metrics.
- Optimize model performance through hyperparameter tuning and cross-validation techniques.
- Improve model transparency by incorporating feature importance analysis and SHAP-based explainability.
- Build a modern and interactive Streamlit web application for real-time mental health score prediction.
- Enable users to explore the dataset, visualize insights, and generate both single and batch predictions through an intuitive interface.
- Demonstrate a complete end-to-end machine learning workflow suitable for academic, portfolio, and learning purposes.
- Promote awareness of how behavioral and lifestyle factors can be analyzed using data science techniques to support informed decision-making while emphasizing that the application is not intended for clinical diagnosis.
AI-Powered Mental Health Prediction
The Mental Health Detection System leverages advanced Machine Learning algorithms to predict a student’s mental health score based on lifestyle, academic performance, physical activity, sleep patterns, stress levels, and social media usage. The system automatically analyzes these factors through a professional preprocessing pipeline and generates an accurate mental health assessment in real time.
Intelligent Data Processing
The application performs multiple preprocessing techniques before making predictions to ensure reliable and consistent results. These include duplicate removal, feature scaling, logarithmic transformation, one-hot encoding, ordinal encoding, feature engineering, and automated data validation. This preprocessing pipeline improves model performance and reduces prediction errors.
Multiple Machine Learning Models
Instead of relying on a single algorithm, the system compares several regression models to identify the most accurate one. Models include:
• Linear Regression
• Ridge Regression
• Lasso Regression
• Decision Tree Regressor
• Random Forest Regressor
• Extra Trees Regressor
• Gradient Boosting Regressor
• AdaBoost Regressor
The best-performing model is automatically selected based on evaluation metrics and cross-validation performance.
Performance Evaluation
The project follows industry-standard regression evaluation techniques.
The trained models are evaluated using:
• R² Score
• Mean Absolute Error (MAE)
• Root Mean Squared Error (RMSE)
• Cross Validation Score
• Training & Testing Performance
• Overfitting Analysis
These metrics ensure that the selected model generalizes well to unseen data while maintaining high prediction accuracy.
| Metric | Description |
|---|---|
| Training R² | Measures how well the model fits the training dataset. |
| Testing R² | Indicates how accurately the model predicts unseen student data. |
| Cross Validation Mean | Average model performance across multiple validation folds. |
| Cross Validation Standard Deviation | Shows the consistency and stability of the model during validation. |
| MAE | Average difference between actual and predicted mental health scores. Lower values indicate better accuracy. |
| RMSE | Penalizes larger prediction errors and measures overall prediction quality. Lower values indicate better performance. |
🏆 Model Performance
Our regression models achieved excellent predictive performance.
Best Model Performance
Training R² : 1.00
Testing R² : 0.91
Cross Validation Mean : 0.91
Cross Validation Standard Deviation : 0.01
Mean Absolute Error : 0.27
Root Mean Squared Error : 0.39
These results demonstrate that the model provides highly accurate predictions while maintaining strong consistency across different subsets of the dataset.

Model Comparision

Distribution
1. Introduction
The Mental Health Detection System is a Machine Learning-based predictive analytics application designed to estimate students’ mental health scores using behavioral, academic, and lifestyle information. By analyzing factors such as social media usage, study hours, stress level, sleep duration, and physical activity, the system provides accurate mental health predictions using advanced regression algorithms.
The project demonstrates a complete end-to-end Machine Learning workflow, from data preprocessing and feature engineering to model training, evaluation, hyperparameter optimization, and deployment-ready model serialization.
2. Objectives
The primary objectives of this project are:
• Predict student mental health scores using Machine Learning.
• Analyze the impact of social media usage on mental well-being.
• Compare multiple regression algorithms.
• Improve prediction accuracy through preprocessing and feature engineering.
• Reduce prediction errors using hyperparameter optimization.
• Demonstrate an end-to-end Machine Learning pipeline.
• Provide an interactive prediction interface.
3. System Overview
The complete workflow of the system consists of:
- Data Collection
- Exploratory Data Analysis
- Data Cleaning
- Feature Engineering
- Data Preprocessing
- Train-Test Split
- Model Training
- Hyperparameter Optimization
- Model Evaluation
- Model Comparison
- Best Model Selection
- Model Saving
- Real-Time Prediction
4. Technologies Used
| Category | Technology |
|---|---|
| Programming Language | Python |
| Data Analysis | Pandas, NumPy |
| Data Visualization | Matplotlib, Seaborn |
| Machine Learning | Scikit-learn |
| Hyperparameter Tuning | RandomizedSearchCV |
| Model Persistence | Joblib |
| Development Environment | Jupyter Notebook |
| Deployment | Streamlit |
5. Machine Learning Model
The project evaluates multiple regression algorithms, including:
• Linear Regression
• Ridge Regression
• Lasso Regression
• Decision Tree Regressor
• Random Forest Regressor
• Extra Trees Regressor
• Gradient Boosting Regressor
• AdaBoost Regressor
The best-performing model is selected based on Testing R², Cross Validation, MAE, and RMSE.
6. Evaluation Metrics
The model performance is assessed using:
• R² Score
• MAE
• RMSE
• Cross Validation Score
• Training Score
• Testing Score
• Overfitting Analysis
These metrics provide a comprehensive assessment of model accuracy, robustness, and generalization.
7. Conclusion
The Mental Health Detection System successfully predicts students’ mental health scores using advanced Machine Learning techniques. Through comprehensive data preprocessing, feature engineering, multiple model comparisons, and hyperparameter optimization, the project achieves reliable predictive performance with strong generalization capability.
The modular architecture and production-ready pipeline make the system suitable for educational demonstrations, research, and future real-world predictive analytics applications.

