# A Deep Learning Framework for Classifications of Pathological Heartbeats from ECG Signals

Muhammad Rashid, Gul Sher Ali Khan, Vijay Singh, Raja Vavekanand

<figure><img src="image_1.png" /></figure>

## To cite this version:

Muhammad Rashid, Gul Sher Ali Khan, Vijay Singh, Raja Vavekanand. A Deep Learning Framework for Classifications of Pathological Heartbeats from ECG Signals. Journal of Surgical Case Reports and Images, 2024, 8 (1), 10.31579/2690-1897/231. hal-04935198

HAL Id: hal-04935198

https://hal.science/hal-04935198v1

Submitted on 7 Feb 2025

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_2.png" /></figure>
# A Deep Learning Framework for Classifications of Pathological Heartbeats from ECG Signals

Muhammad Rashid <fnref n="1" />, Gul Sher Ali Khan <fnref n="2" />, Vijay Singh <fnref n="3" />, Raja Vavekanand <fnref n="3" />*

**\*Corresponding Author:** Raja Vavekanand, Benazir Bhutto Shaheed University Lyari.

**Received Date:** December 13, 2024; **Accepted Date:** December 30, 2024; **Published Date:** January 06, 2024

**Citation:** Muhammad Rashid, Ali Khan GS, Vijay Singh, Raja Vavekanand, (2025), A Deep Learning Framework for Classifications of Pathological Heartbeats from ECG Signals, *J. Surgical Case Reports and Images*, 8(1); **DOI:**10.31579/2690-1897/231

**Copyright:** © 2025, Raja Vavekanand. This is an open access article distributed under the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.

## Abstract

Cardiovascular diseases (CVDs) are a major global health concern, necessitating efficient and reliable diagnostic methods. Electrocardiograms (ECGs) play a vital role in detecting cardiac abnormalities, but their manual interpretation by experts can be labor-intensive and subject to variability. In this study, we propose a novel approach for ECG classification using convolutional neural networks (CNNs) and transfer learning. The model was first pre-trained on a dataset of aggregated ECG signals to capture global patterns and subsequently fine-tuned on individual patient data to tailor predictions to specific characteristics. We utilized the MIT-BIH Arrhythmia Database for training and evaluation. Individual patient-specific models achieved an average balanced accuracy of 94.6%, while transfer learning-based models reached 93.5%. While individual models demonstrated marginally superior performance, transfer learning offered significant advantages in data-scarce scenarios by leveraging pre-trained knowledge. Our findings highlight the potential of transfer learning in addressing challenges such as data scarcity and inter-patient variability.

**Keywords:** ecg signal; deep learning; pathology classifications; transfer learning

## 1.Introduction

Cardiovascular diseases (CVDs) are the leading cause of mortality globally, necessitating efficient diagnostic tools for early detection and management. Electrocardiograms (ECGs) are non-invasive, cost-effective instruments widely used to monitor and diagnose heart conditions such as arrhythmias and myocardial infarction. However, manual interpretation of ECG signals by medical professionals is labor-intensive and prone to human error, underscoring the importance of automated ECG classification systems [1].

Recent advancements in machine learning (ML) and deep learning (DL) have revolutionized the field of medical signal processing, enabling highly accurate and efficient ECG classification [2]. Convolutional Neural Networks (CNNs), in particular, have emerged as the state-of-the-art method for analyzing ECG signals due to their capability to learn hierarchical features from raw data [3,14]. Despite their potential, training CNNs for ECG classification presents challenges, including limited annotated datasets, inter-patient variability, and class imbalance caused by the rarity of pathological events [4]. Transfer learning offers a promising solution to these challenges by leveraging pre-trained models to adapt to specific tasks with

limited data [5,15]. This approach is particularly advantageous for personalized medicine, where ECG signals exhibit patient-specific characteristics [6]. The MIT-BIH Arrhythmia Database [7], a widely used benchmark dataset for ECG analysis, provides an excellent foundation for exploring the efficacy of transfer learning in classifying pathological heartbeats. In this study, we propose a two-stage approach for ECG classification: pre-training a generic CNN on a multi-patient dataset and fine-tuning individual models for specific patients. Our objectives are to evaluate the efficacy of transfer learning in capturing generic and patient-specific features and to compare its performance with traditional patient-specific classifiers.

## 2.Methods

The methodology involves preprocessing ECG signals followed by their fusion into a triple-channel input. These images are then fed into a CNN for classifying pathological heartbeats (Figure 1).

<footnote n="1">¹Muhammad Nawaz Shareef University of Agriculture Multan.</footnote>

<footnote n="2">²Buitsma, Quetta.</footnote>

<footnote n="3">³Benazir Bhutto Shaheed University Lyari.</footnote>
<figure><img src="image_3.png" /><figcaption>Figure 1: System architecture for ECG classification using GAF, MTF, and RP transformations with a CNN-based triple-channel approach.</figcaption></figure>

## 3.1 Dataset

The dataset utilized in this study is the MIT-BIH Arrhythmia Database [1], a benchmark dataset widely used for ECG analysis. It comprises 48 half-hour, two-channel ECG recordings sampled at 360 Hz. Each recording is accompanied by expert annotations categorizing beats into various classes. For this study, the data was pre-processed to normalize signals to the range (0,1), filter noise with a Butterworth bandpass filter (0.4–30 Hz), and segment into 1-second windows (360 samples). Each window was labeled as

normal (0) or abnormal (1). The final dataset consisted of 49,245 labeled samples from 29 patients, after excluding imbalanced samples.

## 3.2 CNN Architecture

A 1D CNN was designed for binary classification of ECG windows. The model comprises four convolutional blocks with 32 kernels (5×5), max pooling (5×5), and ReLU activation. Residual connections inspired by ResNet [2] enhance feature propagation. The flattened output of the convolutional layers feeds into a dense layer with 160 units, followed by a sigmoid-activated binary classifier (Figure 2).

<figure><img src="image_4.png" /><figcaption>Figure 2: The architecture of our CNN</figcaption></figure>

## 3.3 Training

This study employed a two-stage training. Pre-training, generic CNN was pre-trained on the aggregated dataset from all patients. The model optimized binary cross-entropy (BCE) loss using the Adam optimizer with a learning rate of 0.001 and weight decay of 0.0001. Fine-tuning, the pre-trained model was fine-tuned for each patient individually to capture personalized ECG

characteristics (Table 1). Hyperparameters were optimized using grid search for each patient.

$$H_p(q) = - \frac{1}{N} \sum_{i=1}^{N} [y_i \log(p(y_i)) + (1 - y_i) \log(1 - p(y_i))]$$

where $y_i$ is the true label and $p(y_i)$ is the predicted probability.

<table><thead><tr><td>Patient</td><td>Batch Size</td><td>Learning rate</td><td>Weighted Sampling</td><td>Balanced Accuracy</td></tr></thead><tbody><tr><td>100</td><td>4</td><td>0.001</td><td>True</td><td>0.713</td></tr><tr><td>102</td><td>4</td><td>0.001</td><td>True</td><td>1.00</td></tr><tr><td>104</td><td>4</td><td>0.001</td><td>False</td><td>0.993</td></tr><tr><td>105</td><td>4</td><td>0.001</td><td>False</td><td>0.996</td></tr><tr><td>106</td><td>16</td><td>0.001</td><td>True</td><td>0.985</td></tr><tr><td>108</td><td>32</td><td>0.01</td><td>True</td><td>0.776</td></tr><tr><td>114</td><td>4</td><td>0.001</td><td>False</td><td>0.955</td></tr><tr><td>116</td><td>16</td><td>0.001</td><td>True</td><td>0.932</td></tr><tr><td>119</td><td>4</td><td>0.01</td><td>True</td><td>1.00</td></tr><tr><td>200</td><td>32</td><td>0.01</td><td>True</td><td>0.962</td></tr><tr><td>202</td><td>16</td><td>0.001</td><td>True</td><td>0.903</td></tr><tr><td>201</td><td>32</td><td>0.001</td><td>True</td><td>0.925</td></tr><tr><td>203</td><td>4</td><td>0.001</td><td>True</td><td>0.966</td></tr></tbody></table>
<table><caption>Table 1: This Table provides the optimal hyperparameters for each patient, found through grid search based on the balanced accuracy on the validation set.</caption><tr><td>205</td><td>32</td><td>0.001</td><td>True</td><td>0.958</td></tr><tr><td>208</td><td>4</td><td>0.01</td><td>False</td><td>0.977</td></tr><tr><td>209</td><td>4</td><td>0.001</td><td>False</td><td>0.950</td></tr><tr><td>212</td><td>16</td><td>0.001</td><td>True</td><td>1.00</td></tr><tr><td>210</td><td>16</td><td>0.001</td><td>True</td><td>0.943</td></tr><tr><td>213</td><td>4</td><td>0.001</td><td>True</td><td>0.919</td></tr><tr><td>215</td><td>4</td><td>0.001</td><td>True</td><td>100</td></tr><tr><td>217</td><td>4</td><td>0.001</td><td>True</td><td>0.998</td></tr><tr><td>219</td><td>16</td><td>0.01</td><td>True</td><td>0.965</td></tr><tr><td>220</td><td>16</td><td>0.01</td><td>True</td><td>0.955</td></tr><tr><td>222</td><td>32</td><td>0.001</td><td>False</td><td>0.897</td></tr><tr><td>221</td><td>32</td><td>0.001</td><td>False</td><td>0.994</td></tr><tr><td>228</td><td>16</td><td>0.001</td><td>True</td><td>0.986</td></tr><tr><td>223</td><td>16</td><td>0.001</td><td>True</td><td>0.916</td></tr><tr><td>231</td><td>4</td><td>0.001</td><td>True</td><td>0.996</td></tr><tr><td>233</td><td>32</td><td>0.001</td><td>False</td><td>0.988</td></tr></table>

# 4. Experimental Setup

## 4.1 Tasks and Dataset Splitting

The dataset was split into training, validation, and test sets using stratified sampling to preserve the class ratio. An 80-20 split was used for training-validation and test sets, followed by an 80-20 split of the training-validation set to create training and validation subsets. Weighted sampling was applied to handle class imbalance, ensuring the model adequately learned both normal and abnormal classes.

## 4.2 CNN Architecture and Parameters

The proposed CNN model (Figure 2) accepts 1×128 pulse windows as input. It consists of convolutional blocks with 32 kernels (5×5), max pooling, skip connections, and ReLU activation.

The architecture concludes with a dense layer (160 units) and a sigmoid-activated output layer for binary classification. The architecture has 67,169 trainable parameters, suitable for the dataset's size and complexity.

## 4.3 Training Protocols

The CNN was pre-trained on the aggregated dataset from all patients to learn generic features. The Adam optimizer was employed with a learning rate of 0.001, weight decay of 0.0001, and a batch size of 32. The training proceeded for 30 epochs, and the model with the lowest validation loss was retained. Fine-tuning: The pre-trained CNN was fine-tuned individually for each patient using the same architecture and hyperparameters optimized via grid search (Table 2).

<table><caption>Table 1: Parameter Range for Grid Search in Individual Classifiers</caption><thead><tr><td>Parameter</td><td>Range</td></tr></thead><tbody><tr><td>Learning Rate</td><td>{0.001, 0.01, 0.1}</td></tr><tr><td>Batch Size</td><td>{4, 16, 32}</td></tr><tr><td>Weighted Sampling</td><td>{True, False}</td></tr></tbody></table>

## 4.4 Evaluation Metrics

Balanced accuracy was used to evaluate model performance. It is robust against class imbalance and calculated as:

$$ \text{Balanced Accuracy} = \frac{\text{Sensitivity} + \text{Specificity}}{2} $$

# 5. Results

## 5.1 Pre-training Performance

The pre-trained CNN model demonstrated effective learning on the aggregated dataset. (Figure 2) shows the training and validation loss curves, with the lowest validation loss achieved at epoch 16. This model provided a robust starting point for patient-specific fine-tuning (Figure 3).
<figure><img src="image_5.png" /><figcaption>**Figure 3:** Training and validation loss curves over epochs for the pre-training phase.</figcaption></figure>

## 5.2 Individual Classifiers

Baseline classifiers trained on individual patient data achieved an average balanced accuracy of 94.6% on the test set. (Figure 4) presents a histogram of the balanced accuracy for all individual classifiers, where 18 of 29

classifiers scored above 95%, and only one patient's model performed below 75%. Figure 4 shows the training and validation loss and balanced accuracy curves for patient 203, indicating stable convergence and high performance (Figure 5).

<figure><img src="image_6.png" /><figcaption>**Figure 4:** Histogram of the balanced accuracy of the individual classifiers on the test set.</figcaption></figure>

<figure><img src="image_7.png" /><figcaption>**Figure 5.** Loss curve (left) and balanced accuracy (right) plots over epochs for patient 203 for the individual classifier.</figcaption></figure>

## 5.3 Transfer Learning

Fine-tuned models, leveraging pre-trained weights, achieved an average balanced accuracy of 93.5%, slightly below the individual classifiers. (Figure 6) shows the histogram of balanced accuracies for fine-tuned models, where

16 of 29 classifiers achieved above 95%. (Figure 7) compares the balanced accuracies of individual and fine-tuned classifiers, highlighting that fine-tuning boosted performance for certain patients but underperformed in others (Figure 8).
<figure><img src="image_8.png" /><figcaption>**Figure 6:** Histogram of the balanced accuracy of the fine-tuned classifiers on the test set.</figcaption></figure>

<figure><img src="image_9.png" /><figcaption>**Figure 7:** Loss curve (left) and balanced accuracy (right) plots over epochs for patient 203 for the fine-tuned classifier.</figcaption></figure>

<figure><img src="image_10.png" /><figcaption>**Figure 8:** Bar plot of the balanced accuracy for each patient on the test set (individuals, fine-tuning).</figcaption></figure>

The results indicate that while individual classifiers marginally outperform fine-tuned models on average, transfer learning is beneficial in scenarios with limited data. Hyperparameter optimization specific to fine-tuning could further enhance performance.

## 6. Discussion

The results of this study highlight the effectiveness of CNNs in classifying ECG signals into normal and abnormal categories. Individual classifiers achieved higher average balanced accuracy compared to fine-tuned transfer learning models. This suggests that patient-specific models are adept at capturing the unique characteristics of individual ECG signals. However, the transfer learning approach demonstrated competitive performance, with particular benefits for patients with limited training data. The slightly lower accuracy of fine-tuned models may be attributed to the reuse of hyperparameters optimized for individual classifiers during fine-tuning. Fine-tuning-specific hyperparameter tuning could address this limitation and enhance model performance. Additionally, the performance variation among

patients reflects the inter-patient variability in ECG morphology, a known challenge in ECG classification. While the study primarily focused on binary classification, the methodology could be extended to multi-class classification of specific arrhythmia types. Future work could also explore integrating data augmentation techniques, such as adding noise or varying sampling rates, to increase the robustness of the models. Overall, this research demonstrates the potential of transfer learning in ECG analysis and its utility in addressing the challenges of data scarcity and variability.

## 7. Conclusion

This study demonstrates the efficacy of CNNs for ECG classification and evaluates the impact of transfer learning in a binary classification task. Individual classifiers, tailored to specific patients, achieved the highest balanced accuracy, averaging 94.6%. Transfer learning, while slightly less accurate at 93.5%, provided a scalable solution for data-scarce scenarios. The pre-training phase effectively captured global ECG patterns, enabling transfer learning models to adapt to individual patient data. While individual
classifiers had a slight edge in performance, transfer learning proved
advantageous for patients with limited data, highlighting its potential for
practical applications. Future research should focus on optimizing
hyperparameters specific to fine-tuning and incorporating multi-class
classification. Expanding the dataset by integrating additional sources or
applying advanced data augmentation could further improve model
robustness. These advancements will enhance the utility of AI-driven
solutions in personalized healthcare, offering scalable and accurate
diagnostic support in real-world settings.

References

1. Schläpfer, J., & Wellens, H. J. (2017). Computer-Interpreted Electrocardiograms. Journal of the American College of Cardiology, 70(9), 1183–1192.

2. Steinhubl, S. R., Waalen, J., Edwards, A. M., Ariniello, L. M., Mehta, R. R. et al. (2018). Effect of a Home-Based Wearable Continuous ECG Monitoring Patch on Detection of Undiagnosed Atrial Fibrillation. JAMA, 320(2), 146.

3. Ma, J., & Dong, M. (2014). R&amp;D of versatile distributed e-home healthcare system for cardiovascular disease monitoring and diagnosis. *IEEE-EMBS International Conference on Biomedical and Health Informatics* (BHI . . .), 12, 444–447.

4. Minami, K., Nakajima, H., & Toyoshima, T. (1999). Real-time discrimination of ventricular tachyarrhythmia with Fourier-transform neural network. IEEE Transactions on *Biomedical Engineering*, 46(2), 179–185.

5. Inan, O., Giovangrandi, L., & Kovacs, G. (2006). Robust Neural-Network-Based Classification of Premature Ventricular Contractions Using Wavelet Transform and Timing Interval Features. IEEE Transactions on Biomedical Engineering, 53(12), 2507–2515.

6. Coast, D., Stern, R., Cano, G., & Briller, S. (1990). An approach to cardiac arrhythmia analysis using hidden Markov models. IEEE Transactions on Biomedical Engineering, 37(9), 826–836. https://doi.org/10.1109/10.58593

7. Ebrahimi, Z., Loni, M., Daneshtalab, M., & Gharehbaghi, A. (2020). A review on deep learning methods for ECG arrhythmia classification. Expert Systems With Applications X, 7, 100033. https://doi.org/10.1016/j.eswax.2020.100033

8. Hadaeghi, F. (2019). Reservoir Computing Models for Patient-Adaptable ECG Monitoring in Wearable Devices. arXiv. https://doi.org/10.48550/arxiv.1907.09504

9. Moody, G., & Mark, R. (2001). The impact of the MIT-BIH Arrhythmia Database. IEEE Engineering in Medicine and Biology Magazine, 20(3), 45–50. https://doi.org/10.1109/51.932724

10. Mit. (2019). MIT-BIH Arrhythmia Database [Dataset]. In Zenodo (CERN European Organization for Nuclear Research). https://doi.org/10.5281/zenodo.3477542

11. Azizi, S., Mustafa, B., Ryan, F., Beaver, Z., Freyberg, J. et al. (2021). Big Self-Supervised Models Advance Medical Image Classification. 2021 IEEE/CVF International Conference on Computer Vision (ICCV), 3458–3468. https://doi.org/10.1109/iccv48922.2021.00346

12. Kotar, K., Ilharco, G., Schmidt, L., Ehsani, K., & Mottaghi, R. (2021). Contrasting Contrastive Self-Supervised Representation Learning Pipelines. 2021 IEEE/CVF International Conference on Computer Vision (ICCV). https://doi.org/10.1109/iccv48922.2021.00980

13. He, K., Zhang, X., Ren, S., & Sun, J. (2016). Deep Residual Learning for Image Recognition. In 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR). https://doi.org/10.1109/cvpr.2016.90

14. Vavekanand, R., Sam, K., Kumar, S., & Kumar, T. (2024). CardiacNet: A Neural Networks Based Heartbeat Classifications using ECG Signals. Studies in Medical and Health Sciences, 1(2), 1–17. https://doi.org/10.48185/smhs.v1i2.1188

15. Vavekanand, R., & Kumar, T. (2024). Data augmentation of ultrasound imaging for non-invasive white blood cell in vitro peritoneal dialysis. Biomedical Engineering Communications, 3(4), 17. https://doi.org/10.53388/bmec2024017

<figure><img src="image_11.png" /></figure>

This work is licensed under Creative
Commons Attribution 4.0 License

To Submit Your Article Click Here:

Submit Manuscript

DOI:10.31579/2690-1897/231

Ready to submit your research? Choose Auctores and benefit from:

➤ fast, convenient online submission

➤ rigorous peer review by experienced research in your field

➤ rapid publication on acceptance

➤ authors retain copyrights

➤ unique DOI for all articles

➤ immediate, unrestricted online access

At Auctores, research is always in progress.

Learn more https://auctoresonline.org/journals/journal-of-surgical-case-reports-and-images