Exploring heartbeat arrhythmia - part 3
- Vesna Lukic
- Aug 25, 2023
- 3 min read
Updated: Aug 31, 2023
In this last edition of exploring heartbeat arrhythmias, we compare the performance of a 1D CNN and a dense neural network in the classification of five different types of arrhythmias.
In the first part of the series, a preliminary exploratory data analysis was performed. The second part looked at classifying the heartbeat arrhythmia using the kNN algorithm.
The dataset comprises collections of heartbeat signals extracted from the MIT-BIH Arrhythmia Dataset. It has been widely used to explore heartbeat classification using different machine learning techniques. Each segment in the dataset corresponds to a heartbeat and has been preprocessed and segmented for classification.
Data Preprocessing
The dataset is separated into five different classes based on the recorded arrhythmias.
The classes are as follows: Normal (N, Class 0), Supraventricular (S, Class 1) ectopic, Ventricular (V, Class 2) ectopic, Fusion (F, Class 3) and Unknown (Q, Class 4).
The number of samples in each class is analyzed and visualized to gain insights into class distribution.

To address class imbalance, we upsample minority classes to balance the dataset.

Shown below are some example heartbeat signals across all 5 classes:

Model Architectures
1. 1D Convolutional Neural Network (CNN)
We implement a 1D CNN architecture for heartbeat classification. The CNN architecture comprises convolutional layers followed by max-pooling layers. The flattened output is connected to fully connected layers, followed by an output layer. The model has 364,129 parameters in total. The architecture is as follows:

2. Dense Neural Network (NN)
We also construct a dense NN architecture for heartbeat classification. The dense NN architecture consists of multiple fully connected layers followed by an output layer. In total, the model has 353,541 trainable parameters. The architecture is as follows:

Both the CNN and dense neural network models are compiled using the Adam optimizer and categorical cross-entropy loss.
Model Training and Evaluation
We split the dataset into training and testing sets and train both the 1D CNN and dense NN models. The models are trained for 30 epochs each, with an early stopping criteria of 10 epochs. After training, we evaluate the models on the testing set using mean squared error (MSE) and accuracy metrics. Additionally, we generate confusion matrices to analyze the models' performance across different classes.
Results and Discussion
Both the dense neural network and 1D CNN models exhibit promising results with high accuracy for most classes.
On the test set, the 1D CNN network attains a mean square error loss and accuracy of 0.22 and 98.5% respectively. For the dense neural network, the mean square error loss and accuracy is 0.19 and 96.7% respectively.
Shown below is the confusion matrix for the dense neural network:

The 1D CNN confusion matrix is also given below:

The 1D CNN demonstrates near-perfect classification for certain classes and excels in capturing patterns in heartbeat signals. For classes 0, 2 and 4, the performances of both are similar. However, the 1D CNN shows better classification results across class 1 - Supraventricular (86% compared to 70%) and 3 - Fusion (77% compared to 70%).
Perhaps the dense neural network struggles more with classifying the signals in classes 1 and 3 due to the fact that these two classes have the lowest number of original samples, whereas the CNN appears to be more robust to this lack. In regard to class 1, the dense neural network misclassifies these samples as being in class 0 - Normal, for almost 1/3 of the total samples in this class.
Shown below are examples of 10 samples which had a true label of class 1-Supraventricular, however were misclassified as being in class 0 by the dense neural network.

In regard to misclassifications in class 3 - Fusion, aside from having the fewest original samples, this class is a mixture of both normal and ventricular heartbeats, which the dense neural network tends to misclassify as being in class - Normal.
Shown below are examples of 10 samples in class 3 that were misclassified as being in class 0 by the dense neural network.

It is likely that the misclassifications arise due to these samples not displaying the typical pattern of other samples that belong to the same class - they are outliers in terms of their signals.
Conclusion
In this article, we explored the application of 1D CNN and dense NN architectures for heartbeat signal classification. Both models were able to classify heartbeat signals to quite a high degree of accuracy. The CNN model had a slightly higher accuracy compared to the NN model. Overall, both models struggled more to classify the samples in class 1 and class 3. Several examples of samples that were misclassified by the dense neural network are shown (where the true label was class 1- Supraventricular and class 3-Fusion), where both types of signals have been classified as being class - Normal.
By employing neural network models on medical datasets, we can contribute to accurate and efficient heart condition diagnoses.
Comments