Autoencoder-based example in PyTorch for detecting anomalies (seizures) from tabular heart rate features in CSVs. The included notebook (main.ipynb) demonstrates data preparation, training an autoencoder, saving a checkpoint, and evaluating detection performance with reconstruction error and ROC/AUC.
Open main.ipynb and run the cells. The notebook covers:
- loading and concatenating CSV feature files
- feature standardization and conversion to PyTorch tensors
- DataLoader setup and a simple PyTorch AutoEncoder model
- training loop, evaluation, ROC curve and AUC calculation
- saving a model checkpoint
CSV files should contain feature columns and a seizure column with integer labels:
0→ normal (used for training)1→ seizure (anomaly)2or3→ artifact / disagreed (removed by the notebook)
Update the file-glob paths in the notebook before running (examples used in the notebook): path/train/*.csv, path/validation/*.csv, path/test/*.csv.
- Encoder: Linear(16 → 10) → Sigmoid → Linear(10 → 4) → Sigmoid → Dropout(0.05)
- Decoder: Linear(4 → 10) → Sigmoid → Linear(10 → 16) → Sigmoid
- Loss: MSE between input and reconstruction
- Weight init: Xavier/Glorot for Linear layers
Adjust input_size in the notebook if your feature vector length differs from 16.
- Install dependencies (minimal): pip install jupyter pandas numpy scikit-learn matplotlib torch
- Start Jupyter and open main.ipynb: jupyter lab
Or execute the notebook headless: jupyter nbconvert --to notebook --execute main.ipynb --output executed.ipynb
- Batch size: 256
- Optimizer: Adam (lr in notebook: 0.01)
- Epochs: 10 (example)
- Evaluation: per-sample MSE reconstruction error; ROC curve and AUC vs. true labels
- Example AUC shown in the notebook: ~0.6078
- Tune architecture, activations, and learning schedule
- Try threshold selection from training error distribution or use a VAE for probabilistic scores
- Add preprocessing scripts, a requirements.txt, or a train.py to run the pipeline outside the notebook
- main.ipynb — full pipeline
- README.md — this file