A production-ready machine learning system for automated detection and classification of cardiac arrhythmias from raw ECG signals. Built using the MIT-BIH Arrhythmia Database with both classical ML and deep learning approaches.
Cardiovascular diseases are the leading cause of death globally. This project implements an automated ECG analysis pipeline that enables early detection of arrhythmias for applications in remote patient monitoring, wearable devices, and clinical decision support systems.
- End-to-end signal processing pipeline (filtering, baseline correction, R-peak detection)
- AAMI-standard 5-class arrhythmia classification (N, S, V, F, Q)
- Multiple model architectures (Random Forest, XGBoost, 1D CNN, LSTM with Attention)
- Comprehensive evaluation metrics with clinical relevance
- Model explainability using SHAP and Grad-CAM
- Production-ready inference class
| Class | Label | Original Annotations |
|---|---|---|
| N | Normal | N, L, R, e, j |
| S | Supraventricular | A, a, J, S |
| V | Ventricular | V, E |
| F | Fusion | F |
| Q | Unknown/Paced | /, f, Q |
ecg-arrhythmia-classification/
├── data/ # Dataset directory (not tracked)
├── models/ # Saved model weights
├── notebooks/
│ └── EDA.ipynb # Exploratory data analysis
├── src/
│ ├── ecg_preprocessing.py # Signal processing pipeline
│ ├── feature_extraction.py # Hand-crafted feature extraction
│ ├── models.py # Model architectures
│ ├── train.py # Training loop
│ ├── evaluate.py # Evaluation and visualization
│ └── inference.py # Production inference class
├── docs/
│ └── IMPLEMENTATION_PLAN.md
├── requirements.txt
└── README.md
# Clone the repository
git clone https://github.com/Sakeeb91/ecg-arrhythmia-classification.git
cd ecg-arrhythmia-classification
# Install dependencies
pip install -r requirements.txt
# Download the MIT-BIH dataset
python scripts/download_data.py
# Train models
python src/train.py
# Evaluate and generate visualizations
python src/evaluate.py
# Run inference demo
python scripts/demo.pyMIT-BIH Arrhythmia Database (PhysioNet)
- 48 half-hour two-lead ECG recordings from 47 patients
- Sampling rate: 360 Hz
- Approximately 110,000 annotated heartbeats
- Inter-patient split for realistic evaluation
Raw ECG → Bandpass Filter (0.5-40Hz) → Baseline Wander Removal →
R-Peak Detection → Beat Segmentation → Normalization → Model Input
| Model | Accuracy | Weighted F1 |
|---|---|---|
| Classical ML (XGBoost) | 95-97% | 0.93-0.95 |
| 1D CNN | 97-99% | 0.96-0.98 |
| Inter-patient (realistic) | 90-95% | 0.88-0.93 |
- Python 3.8+
- PyTorch 1.9+
- See
requirements.txtfor full dependencies
MIT License
- Moody GB, Mark RG. The impact of the MIT-BIH Arrhythmia Database. IEEE Eng Med Biol Mag. 2001
- AAMI. Recommended Practice for Testing and Reporting Performance Results of Cardiac Rhythm and ST Segment Measurement Algorithms. ANSI/AAMI EC57:2012