Beat by Beat: Classifying Cardiac Arrhythmias with Recurrent Neural Networks

Patrick Schwab, Gaetano Scebba, Jia Zhang, Marco Delai, Walter Karlen · DOI

TL;DR

Researchers at ETH Zurich have developed a machine-learning pipeline that classifies cardiac arrhythmias from short, single-lead ECG recordings by treating them as sequences of individual heartbeats rather than raw waveforms. By combining an ensemble of Recurrent Neural Networks (RNNs) with a soft attention mechanism, the system achieves state-of-the-art performance (0.79 F1 score) while providing clinicians with visual "explanations" of which specific beats triggered a diagnosis.

What Problem Does This Paper Address?

The rise of mobile cardiac event recorders (like smartwatches or handheld ECG pads) has created a deluge of data. However, these devices typically provide only a single lead and very short recordings, making automated classification significantly harder than with traditional 12-lead clinical ECGs.

From a deep learning perspective, raw ECG signals are extremely long sequences (often thousands of time steps), which makes it difficult for standard RNNs to learn long-term temporal dependencies due to vanishing gradients. Furthermore, "black box" models are often mistrusted in medicine; clinicians need to know why a model flagged a recording as Atrial Fibrillation (AF) or another arrhythmia.

Methods

The authors propose a multi-stage classification pipeline that shifts the focus from raw samples to biological units: heartbeats.

  1. Preprocessing & Segmentation: After normalization, the system uses a customized QRS detector to identify R-peaks. It then segments the ECG into a sequence of heartbeats (0.66-second windows). This drastically reduces the sequence length from ~9,000 raw samples to an average of just 33 beats per record.
  2. Feature Extraction: For each beat, the model extracts a mix of hand-crafted features (like RR intervals, wavelet energy, and entropy) and learned features from Stacked Denoising Autoencoders (SDAEs) to capture subtle morphological structures.
  3. Level 1 Ensemble: A diverse set of 15 RNNs (using GRU or BLSTM units) and 4 Hidden Semi-Markov Models (HSMMs) process the beat sequences. Crucially, some RNNs include a soft attention mechanism that assigns a weight to each heartbeat based on its importance to the final classification.
  4. Level 2 Blender: A multilayer perceptron (MLP) acts as a "blender," taking the predictions from the Level 1 models plus global ECG features to produce the final classification (Normal, AF, Other, or Noise).
Figure 1. An overview of our ECG classification pipeline.

Datasets

The study primarily uses the PhysioNet Computing in Cardiology (CinC) 2017 challenge dataset, which contains 12,186 unique single-lead ECG records.

  • Training/Validation: The public portion of the dataset.
  • Test Set: A private set of 3,658 records held by the challenge organizers.
  • Augmentation: To handle class imbalance, the authors supplemented the training data with labeled samples from other PhysioNet databases (e.g., MIT-BIH Arrhythmia Database).

Key Insights and Ideas

  • Biological Downsampling: By reformulating the task as sequence classification over beats rather than samples, the authors bypassed the "long sequence" problem inherent in RNNs. This makes the temporal dimension much easier for the network to navigate.
  • Interpretability via Attention: The attention mechanism acts as a bridge between machine learning and clinical practice. Instead of a single label, the model produces an "attention map." For example, when identifying "Other" arrhythmias, the model often puts high weight on sudden, elongated pauses in the rhythm—exactly what a human cardiologist would look for.
  • Hybrid Modeling: Combining discriminative RNNs with generative HSMMs allowed the ensemble to capture both the morphological nuances of individual beats and the broader statistical properties of the heart rhythm.
Figure 2. A visualisation of the attention values at (top) of two different RNNs over two sample ECG recordings (bottom). The graphs on top of the ECG recordings show the attention values at associated with each identified heartbeat (dashed line). The labels in the left and right corners of the attention value graphs show the settings the model was trained for and their classification confidence, respectively. The recording on the left (A02149) represents a normal sinus rhythm. Due to the regular heart rhythm in the ECG, a distinctive pattern of approximately equally weighted attention on each heartbeat emerges from our RNN that was trained to distinguish between normal sinus rhythms and all other types of rhythms. The recording on the right (A04661) is labelled as an other arrhythmia. The RNN trained to identify other arrhythmias focuses primarily on a sudden, elongated pause in the heart rhythm to decide that the record is most likely an other arrhythmia.

Key Results

The model achieved an average F1 score of 0.79 on the unseen private test set, placing it among the top-performing entries for the CinC 2017 challenge.

Breakdown by class:

  • Normal Sinus Rhythm: 0.90 F1
  • Atrial Fibrillation (AF): 0.79 F1
  • Other Arrhythmias: 0.68 F1

The high performance on Normal and AF classes suggests the model is highly reliable for the most common screening tasks, though the "Other" category remains challenging due to its inherent heterogeneity.

Limitations and Future Work

The authors acknowledge that while the model is performant, it currently relies solely on the ECG signal. They hypothesize that accuracy could be further improved by incorporating contextual metadata, such as patient demographics (age, sex), clinical history, and behavioral data.

Additionally, while the attention mechanism provides a degree of interpretability, it is a "soft" explanation. Future work could involve more rigorous validation of these attention maps against the diagnostic reasoning of expert cardiologists to ensure the models are truly learning clinically relevant features rather than artifacts.

Summary updated

Abstract

With tens of thousands of electrocardiogram (ECG) records processed by mobile cardiac event recorders every day, heart rhythm classification algorithms are an important tool for the continuous monitoring of patients at risk. We utilise an annotated dataset of 12,186 single-lead ECG recordings to build a diverse ensemble of recurrent neural networks (RNNs) that is able to distinguish between normal sinus rhythms, atrial fibrillation, other types of arrhythmia and signals that are too noisy to interpret. In order to ease learning over the temporal dimension, we introduce a novel task formulation that harnesses the natural segmentation of ECG signals into heartbeats to drastically reduce the number of time steps per sequence. Additionally, we extend our RNNs with an attention mechanism that enables us to reason about which heartbeats our RNNs focus on to make their decisions. Through the use of attention, our model maintains a high degree of interpretability, while also achieving state-of-the-art classification performance with an average F1 score of 0.79 on an unseen test set (n=3,658).
BibTeX
@inproceedings{schwab2017beat,
  author = {Patrick Schwab and Gaetano Scebba and Jia Zhang and Marco Delai and Walter Karlen},
  title = {{Beat by Beat: Classifying Cardiac Arrhythmias with Recurrent Neural Networks}},
  booktitle = {CinC},
  year = {2017},
  doi = {10.22489/cinc.2017.363-223},
}
Figure