Comparison of shallow and deep learning methods of ECG signals classi-fication for arrhythmia detection

The research aims to compare the classification performance of arrhythmia classification from the ECG signal dataset from the Massachusetts Institute of Technology–Beth Israel Hospital (MIT-BIH) database. This study uses shallow learning methods: Support Vector Machine, Naïve Bayes, and Random Forest. 1D Convolutional Neural Network (1D CNN), Long Short Term Memory (LSTM), and Gated Recurrent Unit (GRU) are deep learning methods that are used for the study. The models are tested on a dataset with 140 samples that are grouped into four class labels. Each sample has 2160 features. Those models are tested for classification performance. This research shows Random Forest and 1D CNN have the best performance.


Introduction
Nowadays, signal classification methods play an essential role in a wide variety of life. Examples of the implementation of this method are for the classification of music genres and moods [1], the classification of machine conditions [2], and the classification of signals in the health field [3], [4]. One of the signal classification cases in the health sector is the electrocardiogram (ECG) signal classification. ECG is a signal that describes the electrical activity carried out by the heart and is very important in diagnosing heart rhythm disturbances caused by changes in electrical impulses in the heart. This disorder is also known as arrhythmia [4]. One way to help detect heart rhythm disturbances early on automatically can be done with the help of deep learning. This paper compares deep learning methods of arrhythmia classification using ECG signals.
Currently, many studies have been carried out that utilize machine learning or artificial intelligence to recognize ECG patterns and then automatically predict heart condition categories. Machine learning techniques based on shallow learning for heart disease classification are used, such as Random Forest [5], Support Vector Machine (SVM) [6], K-Nearest Neighbors (KNN) [7], Naïve Bayes [8]. The deep learning technique used for the classification of cases of heart disease is Convolutional Neural Network (CNN) [6], Recurrent Neural Network (RNN), and Long Short-Term Memory (LSTM) [4] [6].
In research on the classification of heart disease, there are two treatments for ECG data. The first treatment using raw ECG data was done by [9]. In this study, the selected raw ECG data were classified using the shallow learning type classification method, namely SVM. The second treatment is to analyze the raw ECG signal by transforming the signal. One of the transformation techniques used is the wavelet transform [10]. The raw ECG signal usually consists of different frequency components and even noise, making it difficult for classification algorithms to learn to determine patterns. So the wavelet transform is used to eliminate these things. However, humans recognize arrhythmic patterns from visualization of the raw ECG signal. In addition, the classification of raw ECG signals can lighten the computer's work because it does not perform signal transformation calculations.
Based on this explanation, a comparative study was conducted on classifying raw ECG signals with shallow and deep learning algorithms. The goal is to determine Journal of Computer Sciences Institute 27 (2023) 132-137 which shallow and deep learning algorithms can perform better classification. In addition, this study also aims to determine which classification performance is better between algorithms based on shallow learning and deep learning.
This report is divided into five section: 1) Introduction, 2) Dataset and method section explains the dataset and classification algorithms that are used, 3) Research implementation section explains the steps in implementation of this study, 4) Result, and the last section is 5) Conclusions.

Dataset
The raw ECG signal dataset used in the study is from research [9]. With details as can be seen in Tabel 1. The source of the research data came from the arrhythmia database of the Massachusetts Institute of Technology-Beth Israel Hospital (MIT-BIH). Six seconds of cardiac records resulted in 2160 data points.
Arrhythmias cause the heart to beat faster, slower, or irregularly. The condition causes symptoms such as feeling tired and pain in the chest. To detect arrhythmias, doctors use a heart record or electrocardiogram. An electrocardiogram (EKG) is a recording of heart activity obtained by attaching an electrode to the skin to capture the electric current generated by the heart. A series of heart activities recorded by the EKG can be used as an indicator of a heart rhythm disorder, which doctors or nurses can use to take appropriate action. A normal sample is regular heart rate ECG data, also known as normal sinus rhythm. A normal sample can be visualised in Figure 1, where the heart is beating in a regular sinus rhythm between 60 -100 beats per minute (specifically 82 bpm). Atrial Fibrillation is a type of arrhythmia. In this condition, a rapid heartbeat often causes poor blood flow. The heart's upper chambers (atria) beat out of coordination with the lower chambers (ventricles). These conditions may have no symptoms, but when they do they include palpitations, shortness of breath, and fatigue. Atrial Fibrillation visualization is shown in Figure 2.
Extra heartbeats known as premature ventricular contractions (PVCs) begin in one of the heart's two lower pumping chambers (ventricles). The regular heart rhythm is disrupted by this extra beat, which can sometimes make the chest feel like it is pounding or jumping up and down. This irregular heartbeat is also known as PVC Bigeminy, which is visualized in Figure 3. Ventricular Tachycardia is a condition in which the heart's lower chambers (ventricles) beat very fast. This irregular heartbeat ECG is shown in Figure 4. This condition occurs because of a problem with the heart's electrical impulses. This condition can develop as a complication of a heart attack, or it can occur in people with certain conditions, such as valvular heart disease.

Methods
There are two type learning that are used in this study: shallow learning and deep learning.
Shallow learning is a type of machine learning that learns from data with predetermined features extracted from features. In this study, shallow learning algorithms that are used are Support Vector Machine, Naïve Bayes, and Random Forest.
Vapnik introduced the Support Vector Machine (SVM) in 1992 as a machine learning method that works on the Structural Risk Minimization (SRM) principle, which aims to find a hyperplane to separate two classes in the input space. This method uses hypotheses as linear functions in feature space with high dimensions by implementing a learning bias derived from statistical learning theory. The level of accuracy in the model that the switching process will produce with 134 SVM depends on the kernel functions and parameters. [6].
The Naive Bayes algorithm is a classifier that uses the probabilistic and statistical methods proposed by the British scientist Thomas Bayes to predict future potentials based on past experiences. The main feature of Naïve Bayes is a solid assumption for the independence of each condition of an event. Calculations for comparison of new cases with old cases are indexed based on input parameters with mathematical calculations using probabilities that occur for cases considered similar (Bayesian model). The advantage of Naïve Bayes is that it does not require a lot of data to estimate the parameters needed for classification [8].
Random Forest has many decision trees, which can be hundreds or even thousands of trees, which predict individual classes. The Random Forest aims to form a single representative decision from multiple decision trees. The majority vote of the entire tree can be defined as the result of class predictions [5]. The structure of the Random Forest can be seen in Figure 5  In contrast to shallow learning, deep learning gets features from data from the feature extraction process, which is carried out automatically without human intervention. Deep learning algorithms automatically learn their features and weights, allowing deep learning to use the best features to get the best classification performance. Deep learning algorithms that are used in this study are 1D Convolutional Neural Network (1D CNN), Long Short-Term Memory (LSTM), and Gated Recurrent Unit (GRU).
Wiesel and Hubel first carried out a Convolutional Neural Network (CNN) regarding the virtual cortex in the sense of sight. CNN is an architecture that can be trained and consists of several stages, inputs and outputs. CNN trains and tests each input data through a series of processes, namely the convolutional layer, followed by pooling to extract features from successive input data. The next step is the pooling process. In this process, the data is flattened and then entered into the fully connected-layer process to complete the classification process [12]. Usually, CNN is used to process input data in images as two-dimension data. CNN is also known as 2D CNN. Figure 6 shows an example of a 2D CNN architecture for 2D data.
In 2D CNN, the convolutional layer will produce two-dimensional data. CNN can also be used for onedimensional data cases, for example, signals including ECG. For the case of one-dimensional data, CNN is known as 1D CNN. In 1D CNN, the convolutional layer will run in one dimension and produce one-dimensional data [14].  Recurrent Neural Network (RNN) is an artificial neural network for processing sequential data such as speech recognition and language modelling. Long Short-Term Memory (LSTM) is a variation of RNN that was created to avoid the problem of long-term dependency on RNN [4]. LSTM can remember long-term information, and LSTM also has an iterative processing model like RNN. In the LSTM, there is a path that connects the old context to the new context or what is also known as the cell state, memory cell or memory path. The path makes the values in the old context easily linked to the new context if needed with minor modifications. The LSTM can delete or add information to memory lanes governed by the sigmoid function [6].
LSTM has four gates: forget gate, input gate, cell gate, and output gate. Forget gate is a gate that decides whether information should be removed or not from processing. The input Gate is a gate that decides to determine whether an input will be added to the cell gate memory. The cell gate is a gate that functions as a memory for a layer; this gate's ability is to remember long-term information. The output gate is a gate whose function is to decide what will be produced based on the input and cell gate.
Gated Recurrent Unit (GRU) is an architecture created in 2014 by Kyunghun Cho. GRU provides faster convergence, and the results can be compared with LSTM. GRU also has a smaller error value compared to LSTM. The purpose of the GRU is to make each recurrent unit so that it can capture every relationship (de-Journal of Computer Sciences Institute 27 (2023) 132-137 pendency) in different time scales carried out adaptively. The GRU has a component that regulates the flow of information called the gate, and the GRU here has two gates, namely, the reset gate and the update gate [15].

Research implementation
The steps in the implementation of the research can be seen in Figure 8. Based on the picture above, it can be seen that the raw ECG signal data is divided into 80% training data and 20% as test data. Furthermore, the training data will be used in the training process using the classification algorithm. The classification algorithms used in this study is as follows: From Figure 8, we conduct six experiments to make six classification models. Then each model will be tested using test data. So there are six performance classifications. The research questions raised in the Introduction section can be answered by comparing these performances.
Implementation of shallow learning algorithms using the Python programming language with the Scikit-Learn library. In Table 2 it can be seen the parameters used for each shallow learning algorithm. The implementation of the deep learning's algorithm uses the Python programming language with the Keras and Tensorflow libraries. The architecture and parameters used in each algorithm can be seen in Table 3.

Results
The results of the six experiments conducted in this study can be seen in Table 4. These results show that the highest accuracy for the shallow learning algorithm is 60%, namely by using the Random Forest algorithm. As for the deep learning algorithm, the 1D CNN algorithm works better than other deep learning algorithms with a classification performance of 60%. The classification performance comparison chart can be seen in Figure 9. As explained in section 2.1, Datasets, samples are high dimension data with 2160 features. The Introduction section also mentions that raw ECG data may contain noise and other different frequency components that can interfere with the classification algorithm for pattern recognition. Those problems can cause the low performance of classifications such as SVM, NB, LSTM and GRU. Although the classification performance of RF and 1D CNN cannot be categorized as good, these two algorithms can work better than other algorithms. It is because of the characteristics of RF and 1D CNN.
The characteristic of RF is to create many decision trees that take features randomly. With these characteristics, RF can select the features that can provide the best classification performance. Therefore, the RF performance is better than other shallow learning classification algorithms.
The 1D CNN algorithm has a convolutional layer that functions as a filter which becomes the parameter that is updated in the learning process, and an optimum value is obtained that can provide the best classification performance. This is why the performance of the 1D CNN algorithm is better than the other deep learning algorithms used in this study.

Conclusions
From the results of this study, it can be concluded that the shallow learning type classification algorithm that can provide the best classification performance on raw ECG signals is Random Forest. In comparison, the 1D CNN algorithm is the best for deep learning classifica-tion algorithm types. Both of them produce the same classification performance, which is 60%, so the capabilities of the shallow and deep learning classification algorithms work equally well.
The following research will focus on optimizing the 1D CNN algorithm to get the classification performance of raw ECG signals to predict arrhythmias better. The way we are going to do this is to try out different 1D CNN architectures. In addition, hyperparameter tuning and other fine-tuning will be carried out to produce a better classification model.

Acknowledgements
In this research, the computer system's computation time was provided by the Data Science Lab of the Computer Science Department, Faculty of Mathematics and Natural Sciences, Lambung Mangkurat University. This work was supported by the Program Dosen Wajib Meneliti (PDWM) grant from PNBP Lambung Mangkurat University.