Skip to content

sucharitha1812/ecg-anomaly-detection-vae

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿซ€ ECG Anomaly Detection using Variational Autoencoder (VAE)


๐Ÿš€ Building a Deep Learning System for ECG Anomaly Detection

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.


๐ŸŽฏ Why This Project Matters

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

๐Ÿ“Š Project Snapshot

  • 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

๐Ÿ—๏ธ System Architecture

ECG Signal Data
      โ†“
Data Preprocessing & Normalization
      โ†“
Variational Autoencoder (VAE)
      โ†“
Signal Reconstruction
      โ†“
Reconstruction Error Calculation
      โ†“
Threshold-Based Classification
      โ†“
Anomaly Detection

โš™๏ธ Approach

Variational Autoencoder (VAE)

  • Encoder โ†’ compresses ECG signals into latent space
  • Latent Space โ†’ captures distribution of normal signals
  • Decoder โ†’ reconstructs input signals

Core Idea

  • Train only on normal ECG signals
  • Model learns normal patterns
  • Anomalies produce higher reconstruction error
  • Threshold used for classification

๐Ÿงช Training Strategy

  • Training performed on normal samples only
  • Loss Function:
    • Reconstruction Loss (MSE)
    • KL Divergence
  • Optimized using backpropagation

๐Ÿ“Š Results & Evaluation

๐Ÿ”น Model Performance

  • AUC Score: 0.96
  • Strong separation between normal and anomalous signals
  • Low false negatives (critical for healthcare)

๐Ÿ“ˆ Reconstruction Error Distribution

Reconstruction Error

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.

๐Ÿ“‰ ROC Curve

ROC Curve

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.

๐Ÿ“Š Confusion Matrix

Confusion Matrix

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.

๐Ÿ” Latent Space Visualization (t-SNE)

t-SNE

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.

Overall Result Summary

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.


๐Ÿ“Š Analysis & Insights

  • 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

๐Ÿ’ผ Real-World Impact

  • Early detection of heart abnormalities
  • Integration with wearable health monitoring devices
  • Automated hospital monitoring systems
  • Scalable healthcare AI solutions

โš ๏ธ Limitations

  • Performance depends on threshold selection
  • Dataset may not represent all cardiac conditions
  • Requires tuning for real-world deployment

๐Ÿ”ฎ Future Improvements

  • LSTM / Transformer-based anomaly detection
  • Real-time ECG monitoring systems
  • Deployment as API or cloud service
  • Integration with IoT healthcare devices

Repository structure

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

โ–ถ๏ธ How to Run

pip install -r requirements.txt
jupyter notebook ecg-anomaly-detection-vae.ipynb

๐Ÿ“‚ Dataset

  • Dataset: ECG5000
  • Contains labeled ECG heartbeat signals representing normal and abnormal patterns
  • Converted into binary classification:
    • Normal
    • Anomaly

โœ… Conclusion

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.


๐ŸŽฏ Project Highlights

โœ” Deep Learning for Healthcare
โœ” Unsupervised Anomaly Detection
โœ” End-to-End Pipeline
โœ” Real-world applicability

About

Unsupervised ECG anomaly detection using Variational Autoencoder (VAE) with reconstruction error-based classification, achieving strong performance (AUC: 0.96) for healthcare time-series analysis.

Topics

Resources

Stars

Watchers

Forks

Contributors