This project presents an unsupervised deep learning system for detecting anomalies in ECG (electrocardiogram) signals using a Variational Autoencoder (VAE).
Unlike traditional supervised classification approaches, this system learns the underlying structure of normal heart signals and identifies anomalies based on deviations in reconstruction.
This makes the solution highly applicable to real-world healthcare scenarios where labeled anomaly data is scarce or unavailable.
Healthcare systems require scalable and automated solutions for monitoring heart activity.
Key challenges:
- Limited labeled anomaly data
- High variability in ECG signals
- Need for continuous real-time monitoring
This project demonstrates how deep learning can:
- Learn normal cardiac behavior
- Detect abnormal patterns automatically
- Support early diagnosis and intervention
- Dataset: ECG5000
- Task: Unsupervised Anomaly Detection
- Model: Variational Autoencoder (VAE)
- Approach: Reconstruction Error-Based Detection
- Evaluation Metrics: ROC-AUC, Confusion Matrix, Reconstruction Error
- AUC Score: 0.96
ECG Signal Data
โ
Data Preprocessing & Normalization
โ
Variational Autoencoder (VAE)
โ
Signal Reconstruction
โ
Reconstruction Error Calculation
โ
Threshold-Based Classification
โ
Anomaly Detection
- Encoder โ compresses ECG signals into latent space
- Latent Space โ captures distribution of normal signals
- Decoder โ reconstructs input signals
- Train only on normal ECG signals
- Model learns normal patterns
- Anomalies produce higher reconstruction error
- Threshold used for classification
- Training performed on normal samples only
- Loss Function:
- Reconstruction Loss (MSE)
- KL Divergence
- Optimized using backpropagation
- AUC Score: 0.96
- Strong separation between normal and anomalous signals
- Low false negatives (critical for healthcare)
Interpretation:
The reconstruction error distribution shows a clear separation between normal and anomalous signals. Normal ECG signals exhibit low reconstruction error, while anomalous signals produce significantly higher errors. This confirms that the model has effectively learned normal patterns and can detect deviations reliably.
Interpretation:
The ROC curve demonstrates strong classification performance, with an AUC score of 0.96. This indicates that the model can effectively distinguish between normal and anomalous signals across different thresholds.
Interpretation:
The confusion matrix shows high true positives and true negatives with relatively low false negatives. This is critical in healthcare applications, where missing anomalies can lead to serious consequences.
Interpretation:
The t-SNE visualization shows clear clustering between normal and anomalous signals in latent space, indicating that the model has learned meaningful feature representations.
The model demonstrates strong anomaly detection capability, with clear separation between normal and anomalous signals, high AUC score, and reliable classification performance across multiple evaluation metrics.
- Reconstruction error effectively separates normal and anomalous signals
- Model generalizes well without labeled anomaly data
- Latent space captures meaningful ECG patterns
- Low false negatives indicate strong reliability in detecting anomalies, which is critical in healthcare applications
- Early detection of heart abnormalities
- Integration with wearable health monitoring devices
- Automated hospital monitoring systems
- Scalable healthcare AI solutions
- Performance depends on threshold selection
- Dataset may not represent all cardiac conditions
- Requires tuning for real-world deployment
- LSTM / Transformer-based anomaly detection
- Real-time ECG monitoring systems
- Deployment as API or cloud service
- Integration with IoT healthcare devices
ecg-anomaly-detection-vae/
โ
โโโ README.md
โโโ ecg-anomaly-detection-vae.ipynb
โโโ ecg-anomaly-detection-vae.py
โโโ ecg-anomaly-detection-report.pdf
โ
โโโ images/
โ โโโ reconstruction_error.png
โ โโโ roc_curve.png
โ โโโ confusion_matrix.png
โ โโโ tsne_plot.png
โ
โโโ data/
โโโ ECG5000.zip
pip install -r requirements.txt
jupyter notebook ecg-anomaly-detection-vae.ipynb- Dataset: ECG5000
- Contains labeled ECG heartbeat signals representing normal and abnormal patterns
- Converted into binary classification:
- Normal
- Anomaly
This project demonstrates how Variational Autoencoders can be used for effective anomaly detection in ECG signals without requiring labeled anomaly data during training.
The model successfully learns normal patterns and identifies deviations using reconstruction error, achieving strong performance with an AUC score of 0.96.
This approach highlights the potential of unsupervised deep learning models for real-world healthcare monitoring systems.
โ Deep Learning for Healthcare
โ Unsupervised Anomaly Detection
โ End-to-End Pipeline
โ Real-world applicability



