A machine learning project for detecting motion from ESP32 Wi-Fi Channel State Information (CSI). The pipeline processes recorded CSI measurements, extracts temporal features, and trains an XGBoost classifier to distinguish MOVING from NOT MOVING.
A Streamlit dashboard provides interactive evaluation, error analysis, and SHAP-based explanations of individual predictions.
- CSI validation, transmitter filtering, and per-packet amplitude normalization.
- Sliding-window feature extraction using 6-second windows with a 3-second step.
- Binary classification using 22 CSI-derived features.
- Time-based training and testing with a gap between subsets.
- Classification metrics, confusion matrices, and feature importance plots.
- Interactive prediction inspection and local and global SHAP explanations.
- CSV export of evaluation results.
The preprocessing script expects three recordings in the data/ directory:
| Recording | Scenario | Label |
|---|---|---|
empty_room.csv |
No person in the room | NOT MOVING |
standing_still.csv |
A person standing still | NOT MOVING |
moving.csv |
A person moving | MOVING |
Each CSV must contain:
| Column | Description |
|---|---|
timestamp |
Numeric timestamp in seconds. |
mac |
Wi-Fi transmitter MAC address. |
amplitudes |
String representation of a list containing 64 CSI amplitude values. |
By default, preprocessing selects a transmitter present in all three recordings. A specific transmitter can also be selected using --mac.
Raw recordings and trained model artifacts are not included in the repository.
The pipeline filters packets by transmitter, removes invalid measurements, selects active subcarriers, and normalizes each packet by its mean amplitude.
Recordings are divided into overlapping windows. Windows containing fewer than eight packets are discarded.
Each window is represented by 22 features describing:
- Temporal variation across subcarriers.
- Changes between consecutive packets.
- Amplitude range and drift between the first and last packets.
- Variation and packet-to-packet changes within six subcarrier groups.
An XGBoost classifier predicts movement from the extracted features.
For each recording, the first 70% of windows are used for training. Two windows are skipped before the remaining test portion to separate overlapping training and test windows.
The training script reports accuracy, balanced accuracy, precision, recall, F1, and macro F1. It also saves the model, test predictions, metrics, and diagnostic plots.
The Streamlit application displays:
- Overall classification metrics and a confusion matrix.
- Performance for each recording scenario.
- Predictions filtered by scenario and correctness.
- Movement probabilities for individual windows.
- SHAP feature contributions for selected predictions.
- Global feature importance across test windows.
- Downloadable evaluation results.
The dashboard evaluates recorded data; it does not capture a live CSI stream.
WiFiMotionDetection/
├── model / # Directory name includes a trailing space
│ ├── preprocessing.py
│ └── xgboostmodel.py
└── streamplit_app.py
The data/ and models/ directories are used for local recordings and generated outputs.
Run the following commands from the repository root.
python -m venv .venv
source .venv/bin/activate
pip install numpy pandas matplotlib scikit-learn xgboost streamlit plotlyOn Windows, activate the environment with .venv\Scripts\activate.
Create a data/ directory and add:
data/
├── empty_room.csv
├── standing_still.csv
└── moving.csv
The quotes preserve the trailing space in the current directory name.
python "model /preprocessing.py" --data-dir data --output data/processed_windows.csvTo select a transmitter explicitly:
python "model /preprocessing.py" --data-dir data --mac "AA:BB:CC:DD:EE:FF"python "model /xgboostmodel.py"Generated artifacts are saved in models/, including the trained model, evaluation metrics, test predictions, confusion matrix, and feature importance plots.
streamlit run streamplit_app.pyEvaluation uses later portions of the same three recordings used for training. It provides a preliminary assessment within those recording sessions; performance across independent sessions, rooms, people, and hardware requires further validation. The work on this project is currently in progress, therefore the data collected from ESP-32s is limited.
This is a research prototype for movement detection, not a medically validated system or an epileptic seizure detector.