A web app that predicts your stress level based on your daily smartphone usage habits — and tells you whether your stress is getting better, worse, or staying the same over time.
Most stress apps just tell you "you're stressed right now." This one goes further — it tracks your stress over time and predicts the direction it's heading. Are things getting worse? Are you recovering? It'll tell you, and it'll alert you before things get critical.
Built as part of a pervasive computing project, this app uses a Random Forest model trained on real mobile usage data to predict stress levels from your daily phone habits like screen time, sleep, social media usage, and more.
Not just "your stress is HIGH" — but "your stress has been increasing for 3 days, take action now." Uses a 7-day sliding window and linear regression to detect trends.
Tells you why the model made that prediction — which factors contributed the most (e.g., "High screen time and low sleep are your biggest stress drivers").
You choose how much data to share:
- Full consent → All 12 features used, detailed results
- Limited consent → Only broad features (screen time, sleep, activity)
- Minimal consent → Just screen time and sleep
Smart alerts that don't spam you. Alerts adapt based on:
- Your consent level (more detail = more specific alert)
- Time of day (night-time high stress triggers a "digital detox" alert)
- Repeated stress spikes (escalates to critical alert after 3+ high readings)
- 30-minute cooldown between same-type alerts
Download a full report of your prediction including trajectory, explanation, contributing factors, and consent level used.
| Layer | Technology |
|---|---|
| Backend | Python, Flask |
| ML Models | Random Forest (Classifier + Regressor) |
| Data Balancing | SMOTE (imbalanced-learn) |
| Trend Analysis | Linear Regression (scipy) |
| Visualizations | Matplotlib, Seaborn |
| PDF Generation | ReportLab |
| Frontend Storage | Browser localStorage (for user history) |
stress-detection-app/
│
├── app.py # Main Flask app + all ML logic
├── stress_model.pkl # Pre-trained model
├── requirements.txt # Python dependencies
│
├── static/
│ ├── confusion_matrix.png # Auto-generated on startup
│ └── feature_importance.png # Auto-generated on startup
│
├── templates/
│ └── index.html # Frontend UI
│
├── STRESS_TRAJECTORY_EXPLANATION.md
├── INTELLIGENT_ALERT_SYSTEM.md
├── HOW_TO_GET_3_HISTORICAL_READINGS.md
└── RUN_LOCALHOST.md
git clone https://github.com/SUBASHREE15S/Stress-Detection.git
cd Stress-Detectionpip install -r requirements.txtPlace your mobile_addiction_data.csv file somewhere on your system and update this line in app.py:
csv_path = r"C:\path\to\your\mobile_addiction_data.csv"python app.pyhttp://127.0.0.1:5000/
The model uses these 12 features from your daily phone usage:
| Feature | Description |
|---|---|
| Daily Screen Time (hrs) | Total hours phone screen was on |
| Phone Unlocks Per Day | How many times you picked up your phone |
| Social Media Usage (hrs) | Time on Instagram, Twitter, etc. |
| Gaming Usage (hrs) | Time spent on mobile games |
| Streaming Usage (hrs) | YouTube, Netflix, etc. |
| Messaging Usage (hrs) | WhatsApp, SMS, etc. |
| Work-Related Usage (hrs) | Emails, work apps |
| Sleep Hours | Hours of sleep per night |
| Physical Activity (hrs) | Exercise or movement |
| Time With Family (hrs) | Offline social time |
| Online Shopping (hrs) | Time on shopping apps |
| Push Notifications/Day | Number of notifications received |
Stress Score =
(Screen Time × 2) + (Unlocks × 0.3) + (Social Media × 1.5)
+ (Gaming × 1.5) + (Streaming × 1.2) + (Work Usage × 1.3)
+ (Notifications × 0.2)
− (Sleep × 4) − (Physical Activity × 3) − (Family Time × 2)
The score is then classified into Low / Medium / High using the 33rd and 66th percentiles.
- Every prediction you make is saved with a timestamp
- After 3 or more predictions, linear regression calculates the trend
- Based on the slope:
- Slope > +2.0 → INCREASING
⚠️ - Slope < −2.0 → RECOVERING ✅
- In between → STABLE 📊
- Slope > +2.0 → INCREASING
To quickly test this, click the "🧪 Add Test History" button in the app — it loads 3 sample readings instantly.
| Alert | Trigger | Severity |
|---|---|---|
| Immediate | High stress + increasing trend | 🟠 High |
| Early Warning | Moderate stress + rising trend | 🟢 Low |
| Digital Detox | High stress during night hours (10PM–6AM) | 🔵 Medium |
| Escalated | 3+ consecutive high stress readings | 🔴 Critical |
Alerts have a 30-minute cooldown — no spam. Critical alerts never auto-dismiss.
Flask==3.0.0
pandas==2.1.4
numpy==1.26.2
scikit-learn==1.3.2
imbalanced-learn==0.11.0
matplotlib==3.8.2
seaborn==0.13.0
reportlab==4.0.7
scipy==1.11.4
- Connect to real phone usage APIs (Android Digital Wellbeing, iOS Screen Time)
- Push notifications to mobile
- Persistent user accounts across devices
- Integration with wearables for heart rate and sleep data
ANU SWATHI V.R
SUBASHREE S
LAHARI K.R