Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dataset

## Heart Rate Prediction to Monitor Stress Level

- **Source:** Kaggle - [vinayakshanawad/heart-rate-prediction-to-monitor-stress-level](https://www.kaggle.com/datasets/vinayakshanawad/heart-rate-prediction-to-monitor-stress-level)
- **Size:** 369,289 training samples, 3 CSV files merged on uuid
- **Files used:**
- time_domain_features_train.csv - 19 HRV time-domain features
- frequency_domain_features_train.csv - 11 frequency-domain features
- heart_rate_non_linear_features_train.csv - 4 non-linear features + label

The dataset file is too large to upload directly. Please download from the Kaggle link above.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Stress Level Detection from PPG Sensor Data β€” Model README

## Problem Statement
Multi-class classification of physiological stress levels (No Stress, Interruption, Time Pressure)
using HRV features derived from PPG sensor data.

## Dataset
- Source: [Heart Rate Prediction to Monitor Stress Level](https://www.kaggle.com/datasets/vinayakshanawad/heart-rate-prediction-to-monitor-stress-level)
- Train samples: 369,289 | Test samples: 73,858
- Features: 34 HRV features (time-domain, frequency-domain, non-linear)
- Classes: no stress (54.2%), interruption (28.5%), time pressure (17.3%)

## Models Implemented

| Model | Test Accuracy | Notes |
|---------|--------------|-------|
| ANN | 99.93% | Baseline feedforward, 3 Dense layers |
| 1D-CNN | **99.99%** | Best model, 2 Conv1D layers |
| LSTM | 99.90% | Slowest training (~43s/epoch) |
| GRU | 99.94% | Lighter than LSTM, competitive accuracy |

## Best Model: 1D-CNN
- Architecture: Conv1D(64) β†’ MaxPool β†’ Conv1D(32) β†’ Flatten β†’ Dense(64) β†’ Dense(3)
- Precision / Recall / F1: 1.00 across all 3 classes
- Misclassifications: 10 out of 73,858 test samples

## Preprocessing
- Merged 3 feature CSV files on `uuid` key
- Dropped `uuid` and `datasetId` columns
- Label encoded target (`condition`)
- StandardScaler normalization
- 80/20 stratified train-test split
- Reshaped to (samples, 34, 1) for sequence models

## Conclusion
1D-CNN achieves near-perfect classification while being 4x faster per epoch than LSTM/GRU.
For tabular HRV features, local pattern detection via convolution outperforms recurrent approaches.
ANN is a strong baseline given the well-separated feature space visible in the correlation heatmap.

Large diffs are not rendered by default.

151 changes: 151 additions & 0 deletions Detecting Stress Levels from PPG Sensor Data using ANN/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Detecting Stress Levels from PPG Sensor Data using ANN

## 🎯 Aim

The goal of this project is to predict stress levels using features derived from **Photoplethysmography (PPG) sensor data** by employing multiple deep learning architectures β€” ANN, 1D-CNN, LSTM, and GRU β€” and comparing their performance.

---

## πŸ“‚ Dataset

- **Source:** [Heart Rate Prediction to Monitor Stress Level β€” Kaggle](https://www.kaggle.com/datasets/vinayakshanawad/heart-rate-prediction-to-monitor-stress-level)
- **Training samples:** 369,289 | **Test samples:** 73,858
- **Features:** 34 HRV features across three domains:
- **Time-domain** (19 features): MEAN_RR, SDRR, RMSSD, HR, pNN50, etc.
- **Frequency-domain** (11 features): VLF, LF, HF, LF_HF ratio, etc.
- **Non-linear** (4 features): SD1, SD2, sampen, higuci
- **Target classes:** `no stress`, `interruption`, `time pressure`

---

## πŸ“ Project Structure

```
Detecting Stress Levels from PPG Sensor Data using ANN/
β”‚
β”œβ”€β”€ Dataset/
β”‚ └── README.md ← Dataset source & description
β”‚
β”œβ”€β”€ Images/
β”‚ β”œβ”€β”€ class_distribution.png
β”‚ β”œβ”€β”€ correlation_heatmap.png
β”‚ β”œβ”€β”€ accuracy_loss_curves.png
β”‚ └── confusion_matrix.png
β”‚
β”œβ”€β”€ Model/
β”‚ β”œβ”€β”€ stress-ppg-detection.ipynb ← Full pipeline notebook
β”‚ └── README.md ← Model details & results
β”‚
β”œβ”€β”€ Web App/
β”‚ β”œβ”€β”€ web_app.py ← Streamlit web application
β”‚ β”œβ”€β”€ stress_ppg_cnn_model.h5
β”‚ β”œβ”€β”€ scaler.pkl
β”‚ └── README.md
β”‚
β”œβ”€β”€ README.md ← (this file)
└── requirements.txt
```

---

## 🧠 Models Implemented

| Model | Architecture | Test Accuracy |
|---------|-------------|--------------|
| ANN | 3Γ— Dense layers with Dropout | 99.93% |
| 1D-CNN | 2Γ— Conv1D β†’ MaxPool β†’ Dense | **99.99%** Best |
| LSTM | 1Γ— LSTM(64) β†’ Dense | 99.90% |
| GRU | 1Γ— GRU(64) β†’ Dense | 99.94% |

### Why these models?

| Model | Rationale |
|-------|-----------|
| **ANN** | Strong baseline for tabular HRV feature learning |
| **1D-CNN** | Captures local temporal patterns and short-term signal variations |
| **LSTM** | Handles long-range dependencies in sequential physiological data |
| **GRU** | Lighter LSTM alternative β€” faster training, competitive accuracy |

---

## πŸ“Š Exploratory Data Analysis

### Class Distribution
![Class Distribution](Images/class_distribution.png)

### Feature Correlation Heatmap
![Correlation Heatmap](Images/correlation_heatmap.png)

### Training Accuracy & Loss Curves (1D-CNN)
![Accuracy Loss Curves](Images/accuracy_loss_curves.png)

### Confusion Matrix (1D-CNN)
![Confusion Matrix](Images/confusion_matrix.png)

---

## βš™οΈ Preprocessing Pipeline

1. Merged three feature CSV files on `uuid` key
2. Dropped `uuid` and `datasetId` identifier columns
3. Label-encoded target (`condition`: 0 = Interruption, 1 = No Stress, 2 = Time Pressure)
4. Applied `StandardScaler` normalization
5. 80/20 stratified train-test split
6. Reshaped to `(samples, 34, 1)` for sequence-based models (CNN, LSTM, GRU)

---

## πŸ† Results & Conclusion

**1D-CNN** is the best-performing model with **99.99% test accuracy** (only 10 misclassifications out of 73,858 samples). It achieves near-perfect precision, recall, and F1-score across all three stress classes.

Key findings:
- HRV features are highly discriminative for stress classification β€” even a simple ANN achieves 99.93%
- CNN's local pattern detection outperforms recurrent models for tabular HRV data
- LSTM/GRU are 4Γ— slower per epoch with marginal accuracy difference
- 1D-CNN is the recommended architecture for deployment

---

## 🌐 Web Application

A **Streamlit** web app allows real-time stress level prediction by entering HRV feature values manually.

**To run:**
```bash
cd "Web App"
streamlit run web_app.py
```

---

## πŸ“¦ Libraries & Dependencies

```
numpy
pandas
matplotlib
seaborn
scikit-learn
tensorflow
streamlit
joblib
kaggle
```

Install with:
```bash
pip install -r requirements.txt
```

---

## πŸ‘€ Author

**Juned Pinjari**
- GitHub: [@juned-pinjari](https://github.com/juned-pinjari)
- Contribution: GSSoC 2026

---

*Part of the [DL-Simplified](https://github.com/abhisheks008/DL-Simplified) open-source repository.*
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Web App β€” Stress Level Detection from PPG Sensor Data

## 🌐 Overview

A **Streamlit** web application that predicts stress levels in real-time based on Heart Rate Variability (HRV) features derived from PPG sensor data. The app uses the trained **1D-CNN** model (best performer with 99.99% accuracy).

## πŸš€ How to Run

1. **Install dependencies:**
```bash
pip install streamlit tensorflow scikit-learn numpy pandas joblib
```

2. **Navigate to the Web App folder:**
```bash
cd "Web App"
```

3. **Launch the app:**
```bash
streamlit run web_app.py
```

4. Open your browser at `http://localhost:8501`

## πŸ–₯️ App Features

- **34 HRV feature inputs** organized across three domains:
- Time-domain (19 features): MEAN_RR, SDRR, RMSSD, HR, pNN25/50, KURT, SKEW, etc.
- Frequency-domain (11 features): VLF, LF, HF, LF_HF, LF_NU, HF_NU, TP, etc.
- Non-linear (4 features): SD1, SD2, sampen, higuci
- **One-click prediction** with the trained 1D-CNN model
- **Confidence scores** displayed as progress bars for all three stress classes:
- 😊 No Stress
- 😐 Interruption
- 😰 Time Pressure

## πŸ“¦ Files Required

| File | Description |
|------|-------------|
| `web_app.py` | Main Streamlit application |
| `stress_ppg_cnn_model.h5` | Trained 1D-CNN model (TF/Keras) |
| `scaler.pkl` | Fitted StandardScaler for feature normalization |

## πŸ“ Notes

- The app loads the model and scaler with `@st.cache_resource` for efficiency
- Features are scaled and reshaped to `(1, 34, 1)` before inference (matching the 1D-CNN input shape)
- Default input values are set to typical resting-state HRV values for quick testing
Binary file not shown.
Binary file not shown.
Loading
Loading