Mental Health Score Predictor
A regression model that predicts a person's Mental Health Score (0โ10) from their social media usage habits, sleep, study, physical activity, and stress level.
The goal is simple: understand how daily digital habits and lifestyle factors relate to mental well-being, and offer a working baseline model others can build on.
Model Details
- Model type: Random Forest Regressor (scikit-learn)
- Task: Tabular regression
- Target variable:
Mental_Health_Score(continuous, 0โ10) - Framework: scikit-learn, trained inside a
Pipeline - Saved format:
.pkl(viajoblib)
Intended Use
- Educational / portfolio project exploring the link between digital habits and mental well-being.
- Baseline for further experimentation (feature engineering, other algorithms, hyperparameter tuning).
Not intended for: clinical, diagnostic, or any real-world mental health decision-making. This model is trained on a small, self-reported survey-style dataset and does not represent a validated psychological assessment.
Dataset
- Size: 5,000 rows, 13 columns
- Features used:
Age,Gender,Country,Academic_LevelMost_Used_Platform,Purpose_Of_UseAvg_Daily_Usage_Hours,Daily_UnlocksStudy_Hours,Physical_Activity_Hours,Sleep_Hours_Per_NightStress_Level(ordinal: Low โ Very High)
- Target:
Mental_Health_Score - No missing values in the raw data.
Preprocessing
- Duplicates removed;
Physical_Activity_Hoursclipped at 0 (no negative values). Countrygrouped into top-10 countries +"Other"to reduce cardinality.Study_Hours(right-skewed) log-transformed, then scaled.- Other numeric features standard-scaled.
Stress_Levelordinal-encoded (Low โ Very High).- Remaining categorical features one-hot encoded.
- 80/20 train-test split.
Training & Evaluation
Four models were compared, with Random Forest tuned via Grid Search and Randomized Search:
| Model | Rยฒ (Test) | Rยฒ (Train) | MAE | MSE | RMSE |
|---|---|---|---|---|---|
| Linear Regression | 0.740 | 0.724 | 0.536 | 0.457 | 0.676 |
| Random Forest (default) | 0.878 | 0.981 | 0.347 | 0.215 | 0.464 |
| Random Forest (Grid Search) | 0.872 | 0.969 | 0.358 | 0.225 | 0.474 |
| Random Forest (Random Search) | 0.865 | 0.955 | 0.369 | 0.237 | 0.487 |
The default Random Forest performed best on the test set and is the model
saved (Mental_Health_Model.pkl). Tuned versions traded a bit of test
performance for lower variance โ worth exploring further if generalization to
new data is a priority.
How to Use
import joblib
import pandas as pd
model = joblib.load("Mental_Health_Model.pkl")
sample = pd.DataFrame([{
"Age": 21,
"Gender": "Male",
"Academic_Level": "Undergraduate",
"Most_Used_Platform": "Instagram",
"Purpose_Of_Use": "Entertainment",
"Avg_Daily_Usage_Hours": 4.5,
"Daily_Unlocks": 140,
"Study_Hours": 4.0,
"Physical_Activity_Hours": 2.0,
"Sleep_Hours_Per_Night": 6.5,
"Stress_Level": "Medium",
"Grouped_Country": "Other"
}])
prediction = model.predict(sample)
print(f"Predicted Mental Health Score: {prediction[0]:.2f}")
Note: the model expects the same preprocessing pipeline it was trained with (it's bundled inside the saved
Pipeline), so raw feature columns can be passed directly as shown above.
Limitations
- Trained on a single, likely synthetic/survey-style dataset โ may not generalize to real-world populations.
- Self-reported features (usage hours, stress level) are prone to bias.
- Correlation-based insights should not be read as causation.
- No fairness/bias audit across demographic groups has been performed.
Files
notebook.ipynbโ full workflow: EDA, cleaning, feature engineering, training, tuning, and evaluation.data.csvโ training dataset.Mental_Health_Model.pklโ trained Random Forest pipeline.
License
Released under the MIT License. Use freely for learning and experimentation.