File size: 7,055 Bytes
78dfcb2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df5d376
78dfcb2
 
df5d376
78dfcb2
 
df5d376
78dfcb2
 
 
 
657ed1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df5d376
 
 
 
657ed1f
df5d376
 
 
 
657ed1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
---
language:
- en
license: mit
library_name: xgboost
tags:
- facial-analysis
- stress-prediction
- mental-health
- xgboost
- mediapipe
- computer-vision
- affective-computing
- regression
datasets:
- FER-2013
metrics:
- mae
- rmse
model-index:
- name: facial-stress-predictor
  results:
  - task:
      type: image-regression
      name: Facial Stress Level Prediction
    dataset:
      name: FER-2013
      type: fer2013
    metrics:
    - type: mae
      value: 22.66
      name: Mean Absolute Error
    - type: rmse
      value: 27.29
      name: Root Mean Squared Error
    - type: accuracy
      value: 77.3
      name: Approximate Accuracy
pipeline_tag: image-feature-extraction
---

# Facial Stress Prediction Model 🧠

## Model Description

This model predicts stress levels (0-100 scale) from facial images using geometric facial landmark features. It's designed for real-time stress monitoring applications in healthcare, mental health assessment, and wellness tracking.

**Model Type:** XGBoost Regressor  
**Task:** Facial Stress Level Regression  
**License:** MIT (or specify your license)

## Model Architecture

- **Algorithm:** XGBoost Regressor with gradient boosting
- **Features:** 9 geometric facial landmarks extracted using MediaPipe Face Mesh
  - Eye Aspect Ratio (EAR) - left, right, and average
  - Eyebrow tension - left, right, and average  
  - Mouth openness
  - Jaw width and jaw drop
- **Output:** Continuous stress score (0-100)
  - 0-30: Low stress
  - 30-55: Moderate stress
  - 55-75: High stress
  - 75-100: Extreme stress

## Training Data

- **Dataset:** FER-2013 (Facial Expression Recognition)
- **Samples:** ~4,900 images (700 per emotion category)
- **Emotion Categories:** 7 (happy, neutral, surprise, sad, disgust, angry, fear)
- **Supervision Method:** Weak supervision - emotion labels mapped to stress scores
- **Split:** 80% training (3,920 samples) / 20% testing (980 samples)

### Emotion-to-Stress Mapping

```
happy    β†’ 10  (Very low stress)
neutral  β†’ 25  (Low stress)
surprise β†’ 40  (Mild stress)
sad      β†’ 55  (Moderate stress)
disgust  β†’ 70  (High stress)
angry    β†’ 80  (Very high stress)
fear     β†’ 90  (Extreme stress)
```

## Training Details

### Hyperparameters

- **n_estimators:** 300 trees
- **max_depth:** 6
- **learning_rate:** 0.1
- **tree_method:** gpu_hist (GPU-accelerated) or hist (CPU fallback)
- **objective:** reg:squarederror
- **Feature normalization:** StandardScaler

### Training Infrastructure

- **Training time:** < 2 hours on GPU / < 4 hours on CPU
- **Hardware:** NVIDIA GPU with CUDA support (optional but recommended)
- **Framework:** XGBoost 2.x with scikit-learn
- **Face detection:** MediaPipe Face Mesh (468 landmarks)

## Performance Metrics

- **Mean Absolute Error (MAE):** 22.66 stress points
- **Root Mean Squared Error (RMSE):** 27.29
- **Approximate Accuracy:** 77.3%
- **Target Performance:** 60-70% accuracy for MVP deployment βœ… **Achieved!**

**Training Set Performance:**
- Training MAE: 6.15 stress points
- Training RMSE: 8.12
- Training Accuracy: 93.9%

## Intended Use

### Primary Use Cases

βœ… Mental health monitoring systems  
βœ… Workplace wellness applications  
βœ… Telemedicine platforms  
βœ… Research in affective computing  
βœ… Educational tools for stress recognition

### Out-of-Scope Use Cases

❌ Clinical diagnosis without professional oversight  
❌ High-stakes decision making (hiring, security clearance, etc.)  
❌ Surveillance or privacy-invasive applications  
❌ Biased or discriminatory profiling

## How to Use

### Installation

```bash
pip install xgboost scikit-learn opencv-python mediapipe numpy
```

### Inference Example

```python
import pickle
import cv2
import numpy as np
from mediapipe import solutions

# Load model and scaler
with open('stress_predictor.pkl', 'rb') as f:
    model = pickle.load(f)
with open('feature_scaler.pkl', 'rb') as f:
    scaler = pickle.load(f)

# Initialize MediaPipe Face Mesh
mp_face_mesh = solutions.face_mesh
face_mesh = mp_face_mesh.FaceMesh(
    static_image_mode=True,
    max_num_faces=1,
    min_detection_confidence=0.5
)

# Extract features from image (using FacialFeatureExtractor class)
# ... feature extraction code ...

# Predict stress level
features_scaled = scaler.transform(features.reshape(1, -1))
stress_level = np.clip(model.predict(features_scaled)[0], 0, 100)

print(f"Predicted Stress Level: {stress_level:.1f}/100")
```

## Limitations and Biases

### Known Limitations

- **Weak supervision:** Model trained on emotion labels, not actual stress measurements
- **Dataset bias:** FER-2013 may not represent all demographics equally
- **Context-agnostic:** Doesn't account for situational context
- **Still images only:** Trained on static images, not video sequences
- **Lighting sensitivity:** Performance may degrade in poor lighting conditions

### Bias Considerations

- Training data may have demographic imbalances
- Facial landmark detection may perform differently across ethnicities
- Should be validated on diverse populations before deployment

## Ethical Considerations

⚠️ **Privacy:** Ensure informed consent when processing facial images  
⚠️ **Transparency:** Users should know when stress analysis is being performed  
⚠️ **Accountability:** Results should be reviewed by qualified professionals in clinical settings  
⚠️ **Fairness:** Monitor for performance disparities across demographic groups

## Model Files

- `stress_predictor.pkl` - Trained XGBoost model (main file)
- `feature_scaler.pkl` - StandardScaler for feature normalization
- `model_metadata.pkl` - Training configuration and metrics

## Citation

If you use this model in your research or application, please cite:

```bibtex
@misc{facial_stress_predictor_2026,
  author = {Your Name/Organization},
  title = {Facial Stress Prediction Model},
  year = {2026},
  publisher = {HuggingFace},
  howpublished = {\url{https://huggingface.co/your-username/model-name}}
}
```

## Contact & Support

- **Repository:** [GitHub Link]
- **Issues:** [GitHub Issues Link]
- **Contact:** [Your Email or Contact Info]

## Changelog

**v1.0.0** (January 2026)
- Initial release
- XGBoost regressor trained on FER-2013
- 9 facial landmark features
- Target: 60-70% accuracy achieved

---

## Technical Details

**Dependencies:**
- Python >= 3.8
- xgboost >= 2.0.0
- scikit-learn >= 1.0.0
- opencv-python >= 4.5.0
- mediapipe >= 0.10.0
- numpy >= 1.20.0

**Model Size:** ~XXX MB (update based on actual file size)

**Inference Speed:** ~XX ms per image on CPU / ~XX ms on GPU (update with benchmarks)

---

**License:** [Specify your license - MIT, Apache 2.0, etc.]

**Last Updated:** January 10, 2026

---

## Remember to Update:

1. ✏️ Performance metrics (MAE, RMSE, Accuracy) with your actual results
2. ✏️ Contact information and GitHub links
3. ✏️ Model file sizes and inference speed benchmarks
4. ✏️ Specify your chosen license
5. ✏️ Update citation details with your information
6. ✏️ Add actual repository URLs