Automatic detection of arrhythmias from an ECG signal using an auto-encoder and SVM classifier

Millions of people around the world are affected by arrhythmias, which are abnormal activities of the functioning of the heart. Most arrhythmias are harmful to the heart and can suddenly become life-threatening. The electrocardiogram (ECG) is an important non-invasive tool in cardiology for the diagnosis of arrhythmias. This work proposes a computer-aided diagnosis (CAD) system to automatically classify different types of arrhythmias from ECG signals. First, the auto-encoder convolutional network (ACN) model is used, which is based on a one-dimensional convolutional neural network (1D-CNN) that automatically learns the best features from the raw ECG signals. After that, the support vector machine (SVM) classifier is applied to the features learned by the ACN model to improve the detection of arrhythmic beats. This classifier detects four different types of arrhythmias, namely the left bundle branch block (LBBB), right bundle branch block (RBBB), paced beat (PB), and premature ventricular contractions (PVC), along with the normal sinus rhythms (NSR). Among these arrhythmias, PVC is particularly a dangerous type of heartbeat in ECG signals. The performance of the model is measured in terms of accuracy, sensitivity, and precision using a tenfold cross-validation strategy on the MIT-BIH arrhythmia database. The obtained overall accuracy of the SVM classifier was 98.84%. The result of this model is portrayed as a better performance than in other literary works. Thus, this approach may also help in further clinical studies of cardiac cases.


Introduction
Every year, approximately 17.9 million people are affected by cardiovascular diseases (CVD) [1]. An abnormal condition arises when the heart beats fast, slow, or with an irregular rhythm, such irregular activity of the heart can lead to high-risk heart disease and even sudden death [2][3][4][5][6][7][8].
Arrhythmia is one such abnormal condition that can lead to serious CVD in people progressing with age. The most common arrhythmias include LBBB, RBBB, PB, and PVC, which can be detected with the help of ECG signals [6][7][8][9][10]. The detection of these arrhythmias requires a detailed examination of ECG recordings by cardiologists, which is a tedious and time-consuming process. Furthermore, there may be significant changes in the ECG signals that get unnoticed by the naked eyes due to the presence of small variations [11]. In the past few decades, numerous machine learning (ML) and deep learning (DL) methods have been developed to automate the identification of arrhythmias. Most of the authors have applied ML techniques for the classification of ECG signals and have identified different types of arrhythmia beats. Before applying ML techniques, many have also used pre-processing and feature extraction methods on ECG signals. The pre-processing function is often used to eliminate noise and detect the QRS complex in an ECG signal, it is also used for segment and amplitude normalization of each ECG cycle [12]. Extraction of features from ECG signals is an important procedure for arrhythmia detection that has been used by several authors in their work. The features 1 3 that have been proposed in the literature are morphological features [13][14][15], temporal features [14][15][16], Hermite basis function [17], higher-order statistics (HOS) [17,18], personalized features [19], etc. It is difficult to extract these features from large ECG signals because feature extraction depends and requires prior knowledge of ECG signals. In recent years, DL-based models have been widely used for ECG signal analysis and arrhythmia identification, which perform automatic feature learning from ECG signal datasets [20]. The most important property of DL techniques is that they learn the best features automatically from the database whereas in traditional feature extraction, different methods are used on datasets. DL is highly expressive in learning because of its deep structure. The feature extraction step is important for the effective classification of arrhythmic heartbeats, as the best features lead to better performance of the model. These features extracted are fed into the ML model for the classification of arrhythmias. Various ML algorithms, such as k-nearest neighbor (K-NN) [21], SVM [22], and random forest [23], have been used in the literature for different types of arrhythmia classification. As per Table 1, many authors have proposed various CAD systems for detecting and classifying arrhythmia heartbeats on small ECG datasets and have achieved high-performance accuracy using different feature extraction techniques.
In this study, a new combination of the ACN-SVM model is proposed to improve the performance of the automated arrhythmic heartbeat classification model. The contributions of this study include a CNN-based ACN that is used to learn features from segmented ECG signals and an SVM classifier that is used to classify five different types of arrhythmia beats based on the features successfully learned by the ACN. In the ACN, there is an auto-encoder that learns high-level features from the ECG signal database. SVM is a classifier that outperforms several other classification methods. We investigate the performance of SVM as a multi-class classification method in which the input feature dimensions are fixed at each classification step and freely selected at the previous classification step. In this paper, we use a raw ECG signal database before applying the SVM classifier. An ACN is used that encodes the data automatically, and then these encoded features are fed to the SVM classifier design to distinguish between NSR and LBBB, RBBB, PB, and PVC. Performance analysis is carried out using the MIT-BIH arrhythmia database. We have compared our ACN-SVM model with other existing classifiers that have been mentioned in several different studies on the same database. The performance of the ACN-SVM model is achieved in terms of the overall accuracy of 98.84%, an average accuracy of 98.84%, the precision of 97.58%, and the sensitivity of 98.24%, respectively. The achieved results have shown better performance in comparison to other previous works. Rest of the paper, the sections are arranged in the following order: Section two, "Materials and methods", which describes the datasets and methods that were used in the experiment, section three shows the "Experiment Result," which presents the results of the experiment, followed by section four, "Discussion" that describes the experimental results along with their comparison with other existing works. Finally, the conclusion is presented in the fifth section.

Materials and methods
The flow diagram of the proposed work for the ECG signal classification to detect arrhythmia from the ECG dataset is given in Fig. 1. In this study, the dataset is first normalized using the z-score normalization method. After normalization, the recorded dataset of each patient is segmented into heartbeats based on the annotation file provided with the database by the cardiologist. The segmented dataset is then fed into an auto-encoder-based CNN that learns the ECG signal features. Finally, an SVM classifier is used to classify the five types of arrhythmia beats.

Database used
In this study, we have collected ECG data from the MIT-BIH arrhythmia database that is an open-source and freely available on the PhySioNet website [37]. It contains 48 records of cardio patients, each of which contains reference annotation files for each beat. The 100 series has 23 recordings from a routine clinical recording of a person, whereas the 200 series contains recordings from an unusual but clinically significant case of arrhythmias that were not adequately shown in the 100 series recordings. Each record is approximate 30 min long and each heartbeat labeled by two or more cardiologists is annotated to indicate the class of heartbeats [38]. Figure 2 shows a graphical representation of the five different types of ECG signals. Figure 2a shows the typical cardiac beat when the heart is functioning normally. If there is an abnormality in the conduction of the electrical pulse generated by the sinoatrial node in the left/right bundle branch, depolarization is delayed. It is composed of two variants of the bundle branch block, LBBB, and RBBB respectively. The LBBB Fig. 2b represents a problem on the left side of the heart and may be visualized by a wide QRS complex, RBBB, Fig. 2c, represents a problem on the right side of the heart and can be visualized by a large QRS complex. The PB is an atrial paced rhythm that occurs when the atria are paced but not the ventricles, Fig. 2d, and can be visualized by a narrow QRS complex. PVCs Fig. 2e, are very dangerous as compared to other types of heart rhythms.  [20] Ye et al.
In this paper, an SVM classifier was used for the classification of different types of heartbeats based on a combination of morphological and dynamic features. The morphological feature was extracted using independent component analysis and wavelet transform while R-R interval is a dynamic feature. These features were applied to SVM for the classification of sixteen types of heartbeats using the MIT-BIH arrhythmia dataset [24] Sharma et al.
In this study, the ECG dataset was decomposed using wavelet decomposition with a dyadic orthogonal filter bank, which minimized stop-band energy and fuzzy entropy features. The extracted features were applied to the K-NN classifier to classify five types of heartbeats [25] Ebrahimnezhad et al. The ECG signal was pre-processed and a multi-resolution wavelet analysis found an R peak. The linear predictive coefficients of the QRS complex were fed into the probabilistic neural network and SVM classifiers.
Both classifiers were trained and tested to measure statistical performance. The experiment was conducted on the MIT-BIH dataset for the detection of five different types of arrhythmia beats [26] Thomas et al.
The multilayer back propagation neural network was used to classify five different types of arrhythmia beats from the MIT-BIH arrhythmia dataset. The classification was performed on extracted features based on the discrete wavelet transform and the dual-tree complex wavelet transform [27] Pandey et al.
The authors presented feature extraction methods based on HOS, wavelets, morphological descriptors, and R-R intervals. These features were fed into a long short-term memory network (LSTM) model for the classification of the MIT-BIH arrhythmia datasets into five different types of arrhythmia beats [28] Nurmaini et al.
A deep neural network was used for detecting ten different types of arrhythmia beats. The deep auto-encoder model was used to extract features from the MIT-BIH arrhythmia datasets. The pre-training and fine-tuning processes were done directly from raw ECG signals using a deep auto-encoder and a deep neural network, respectively [29] Hong et al. This paper suggests a two-stage approach consisting of feature extraction and classification. As part of the feature extraction procedure, both engineered and DL based features were retrieved. The authors discussed feature aggregation methods for combining these features and creating fixed-dimensional feature vectors.
In the second step, they generate multiple gradient-boosting decision trees and combine them to obtain the final classification results. The ensembled approach performs better than an individual classifier in identifying arrhythmia and gives more accurate results on the PhysioNet/Computing in Cardiology challenge 2017 database [30] Yang et al.
The authors presented an ECG arrhythmia classification technique based on the softmax regression model. The stacked sparse auto-encoders learned features from the MIT-BIH arrhythmia data set, which was performed to be efficient in extracting "in-depth" features [31] Yildirim et al.
The author proposed a 1-D CNN model for classifying arrhythmia beats into 17 classes. An end-to-end model was established in this model to analyze 10-s long-duration ECG signal fragments from one lead of 45 subjects from the MIT-BIH arrhythmia database [32] Oh et al.
In this work, an automated detection method based on CNN and LSTM for the diagnosis of NSR, RBBB, LBBB, PVC, and atrial premature beats (PAC) on ECG data is proposed. ECG segments of varying lengths were taken from the MIT-BIT arrhythmia database. The performance of the model in the handling of variable-length data was evaluated using a ten-fold cross-validation technique, which resulted in an accuracy of 98.10% [33] Hou et al.

Normalization and heartbeat segmentation
The technique of normalization, normalizes the mean central values with a unit standard deviation. The mean and standard deviation of normalized scores on calculation will be 0 and 1 respectively. The Z score is determined [39] and is defined by Eq. 1.
where, X = Input variable, = Mean of the distribution, = Standard deviation of distribution.
To obtain different types of heartbeats, the ECG signal is split into 300 sample chunks based on the annotation file given in the MIT-BIH database. The 300 samples are selected because the arrhythmia class is much faster than normal heartbeats. In the segmentation process [40], the position of the R peak is first determined using annotation file information, and then 149 sample points are taken before and 150 sample points after the R peaks, respectively. Similarly, all ECG signals are segmented having 300 data samples in each heartbeat segment.

Proposed deep convolution auto-encoded network
The ACN is capable of encoding data at the input layer and reconstructing it at the output layer, to reproduce the input signal as similar as possible. This is accomplished by training the neural network to change the input data while ensuring that the relevant information is not lost in the encoding phase [22,41]. This procedure enables the machine to generate a feature extraction mechanism by identifying the most relevant parameters in the ECG signals. Let's consider the input vector of auto-encoder x ∈ [0, 1] d that maps the hidden representation y ∈ [0, 1] d between input-output mappings.
where W is the weight matrix of d Χ d, b is a bias vector and ReLu (Rectified Linear Unit) is the activation function. The hidden output y is again mapped back to reproduced vector z ∈ [0, 1] d . Here, the ACN keeps on learning to get the best weights. This is done by feedback sent from output periodically to update weights until the best combination is found. ACN's main objective is to compress each heartbeat segment with the least loss, to achieve this, an ACN has been designed to compress the segmented data and extract auto-encoded features from each encoded heartbeat window. The ACN has four convolution layers and four max-pooling layers for extracting features by convolving the input features produced by the intermediate layer link convolution and max pooling. The function of ReLU is to map all negative values to zero and obtain positive values so that the training can be fast and more effective. The activation function of this layer has been normalized using the batch normalization layer. Here, we have taken the input length of each window as 300 weight vector that is passed on to the first convolution layer with kernel size 20. After convolution, the output is applied to the max-pooling layer with a (2, 2) filter and stride 2. The pooling layers generally reduce the size of feature vectors, this indicates that the output matrix is just half the size of the input matrix. The batch normalization layer is used to normalize the activation output of the max-pooling layer. Similarly, the 3rd, 5th, and 7th convolution layer process are performed correspondingly using max-pooling with batch normalization and kernel sizes of each convolution layer being 10, 3, and 1. Table 2 gives the description of each convolution and max-pooling with batch normalization output. After the last layer, we used a flatten layer which gives the 60 encoded features of each heartbeat segment. These features are given to the SVM classifier for the classification of arrhythmia beats.

Support vector machine classifier
SVM is based on the concept of finding the optimal hyperplane between data values corresponding to distinct classes [22,42,43]. In the two classes, +veclass and,−veclass , the goal is to find a hyperplane that maximizes the margin. This hyperplane is defined as the set of points x satisfying: where, x is the i-dimensional input vector x 1 , x 2 , … … ..x i , w is a weight vector for learning parameter and b (scalar value) is a bias. The margin is defined by the equation: Margin is scale-invariant, which is an important property of SVM. The data is linearly separable if the hyperplane separates the classes in the dataset perfectly. The hyperplanes can be written as follows: The training aims to find the optimal hyperplane that can be achieved by maximizing the distance of separation between the two planes: For the points that are close to the hyperplane: Thus, to maximize the margin, we will have to minimize the term ‖w‖ . It would be difficult to solve min‖w‖ because of the square root involved in the calculation of ‖w‖. Therefore, min‖w‖ 2 is used as the optimization problem to make it easier. For a given set of learning data x i for i = 1, 2, … … … … .m , a non-negative slack variable: , if 0 < < 1, the data do not have the maximum margin but are still correctly classified. But if i ≥ 1, the data are misclassified by the optimal hyperplane. The formulation of optimization issue for the SVM is given as: where C is a margin parameter that controls the trade-off between maximizing the margin and minimizing the training error, j is a positive slack variable indicating the distance of x i from the decision boundary. The SVM may be represented using Lagrange multipliers α. The response to the Lagrange multipliers problem is found by solving a quadratic programming problem [43]. The SVM decision function can be given as: We are minimizing this with respect to w and b, and maximizing with respect to .
The kernel is the radial basis function (RBF) where σ is the parameter which controls the radius and σ > 0 In this experiment, the RBF kernel is used as an SVM kernel function. All ECG segments that have different types of heartbeats are mapped to the feature space using the ACN that has been explained above. The above-encoded features obtained by the ACN model are divided into two parts: training and validation. First, the SVM model is trained on a training dataset of 90% of the total features, and the remaining 10% of the dataset is validated to classify heartbeat arrhythmias.

Experimental result
The proposed model has been trained and validated on a desktop Intel i-5 CPU with 8 GB RAM. The Keras and Tensorflow packages are used with the Python programming language. In this study, we used the MIT-BIH arrhythmia database to measure the statistical performance of the proposed model. A total of 88,075 heartbeats were used for training the model and 9786 heartbeats were used for validation. The parameters (C and γ) of the SVM classification (11) are adjusted to obtain the most optimal classification performance. The values of C and γ is important for the classification, so we first determined the optimal parameters C and γ using ten-fold cross-validation techniques. First, divide the entire dataset into ten equal sections for ten-fold cross-validation strategies. Nine out of these ten sections are used for training purposes and the rest are used for model validation. This process was repeated ten times, where each time a different test set is used to validate the model. The test samples are those samples of the dataset which have not been seen in the training phase. Thus, ten-fold validation is performed on the dataset. The average of ten-fold SVM classification results for all classes of heartbeats is shown in the confusion matrix Table 3. This experiment uses an SVM classifier to classify heart rhythms into five different classes based on training and validation datasets. The diagonal values in Table 3 represent the beats that have been accurately identified as belonging to their respective classes. Based on the confusion matrix for the validated dataset, it is clear that 28 NSR beats, 15 LBBB beats, 11 RBBB beats, 1 PB beat, and 58 PVC beats are misclassified. Based on the confusion matrix values such as true positive (TP), false positive (FP), true negative (TN), and falsenegative (FN), the model performance is evaluated in terms of accuracy, sensitivity, and precision [27]. Table 4 illustrates how the values of TP, FP, TN, and FN have been used to determine evaluation parameters.
The statistical performance indicates the proposed ACN-SVM model for five classes that are summarized in Table 5, which contains the sensitivity, precision, and accuracy. The experimental results indicate that the proposed method can classify the heartbeats into five different classes with an overall accuracy of 98.84% using the ACN-SVM model.
The model has achieved an average precision of 97.58%, an accuracy of 99.53%, a sensitivity of 98.24%, and overall accuracy of 98.84%. The advantage of developing this model is that it is an end-to-end classifier that does not require preprocessing of the ECG signal. The results demonstrate excellent classification accuracy, indicating that the proposed method is an effective way for cardiologists to detect arrhythmia using ECG signals. Oh et al. [32] also used an

Discussion
There are several studies in the literature based on the classification problem of ECG datasets that have been obtained from the publicly available MIT-BIH arrhythmia database. The classification performance [44][45][46] of the proposed model is compared with the state-of-the-art approach in Table 6. Li et al. [47] performed feature extraction and classification of six different types of heartbeats using a genetic algorithm back propagation neural network for classification and feature extraction using wavelet packet decomposition. According to statistics, the result achieved a clas-

Conclusion
This work is focused on the classification of different types of arrhythmia beats using ML technique based on deep auto-encoded features. The ACN-SVM model is employed in the MIT-BIH arrhythmia database to identify four types of arrhythmia beats with one normal heartbeat. The SVM classifier was trained using learned features from the ACN model and then validated on a test data set by applying The ratio of TP among all classified positives Sensitivity

TP TP+FN
The ratio of TP among the entire set of positives Accuracy

TP+TN TP+FN+FP+TN
The widely used metric for determining the overall model performance

Declarations
Conflict of interest Author Manoj Kumar Ojha declares that he/she has no conflict of interest. Author Dr. Sulochna Wadhwani declares that he/she has no conflict of interest. Author Dr. Arun Kumar Wadhwani declares that he/she has no conflict of interest. Author Dr. Anupam Shukla declares that he/she has no conflict of interest.
Ethical approval This article does not contain any studies with human participants or animals performed by any of the authors.