# Combining Rhythm Information between Heartbeats and BiLSTM-Treg Algorithm for Intelligent Beat Classification of Arrhythmia

Authors: Jinliang Yao; Runchuan Li; Shengya Shen; Wenzhi Zhang; Yan Peng; Gang Chen; Zongmin Wang
Journal: Journal of Healthcare Engineering
 (2021)

---

## Abstract

Arrhythmia is a cardiovascular disease that seriously affects human health. The identification and diagnosis of arrhythmia is an effective means of preventing most heart diseases. In this paper, a BiLSTM-Treg algorithm that integrates rhythm information is proposed to realize the automatic classification of arrhythmia. Firstly, the discrete wavelet transform is used to denoise the ECG signal, based on which we performed heartbeat segmentation and preserved the timing relationship between heartbeats. Then, different heartbeat segment lengths and the BiLSTM network model are used to conduct multiple experiments to select the optimal heartbeat segment length. Finally, the tree regularization method is used to optimize the BiLSTM network model to improve classification accuracy. And the interpretability of the neural network model is analyzed by analyzing the simulated decision tree generated in the tree regularization method. This method divides the heartbeat into five categories (nonectopic (N), supraventricular ectopic (S), ventricular ectopic (V), fused heartbeats (F), and unknown heartbeats (Q)) and is validated on the MIT-BIH arrhythmia database. The results show that the overall classification accuracy of the algorithm is 99.32%. Compared with other methods of classifying heartbeat, the BiLSTM-Treg network model algorithm proposed in this paper not only improves the classification accuracy and obtains higher sensitivity and positive predictive value but also has higher interpretability.


---

## Body

## 1. Introduction

With the improvement of people’s living standards, the incidence and mortality of cardiovascular diseases are increasing year by year and are accompanied by a younger trend [1]. Arrhythmia is a common cardiovascular disease, which may endanger people’s lives in serious cases [2]. Therefore, the accurate detection of arrhythmia to prevent heart disease has a very important significance. Electrocardiogram (ECG), as a comprehensive expression of cardiac electrical activity on the body surface, contains a wealth of physiological and pathological information reflecting cardiac rhythm and electrical conduction and is one of the important bases for diagnosis of heart disease and evaluation of cardiac function [3]. Different types of arrhythmias can be identified and diagnosed by analyzing the ECG waveform. Traditional ECG waveform analysis is performed manually by medical personnel, who need to give a diagnosis based on cardiovascular disease diagnosis rules and personal experience. Due to the individual differences of patients and the complexity of diseases, there are many types of ECG. In addition, some arrhythmias occur only occasionally in the daily life of the patients, and the ECG data need to be recorded for a long time. Therefore, the amount of collected ECG data is huge, which brings a heavy burden to doctors. Under the circumstances, mistakes, missed inspections, or misdetections easily occur. With the rapid development of computer technology and electronic information technology, the computer has become an indispensable and important tool of medical modernization, and computer-aided medical treatment has penetrated into every corner of medical service [4]. In recent years, increasing attention has been paid to the study of computer-aided analysis algorithms for electrocardiography, particularly those that can accurately and rapidly identify and diagnose arrhythmias. The automatic classification and diagnosis algorithm of ECG signals can save doctors’ time by helping them better judge the symptoms of arrhythmia quickly. In addition, it can provide good healthcare in areas where medical resources are scarce.This paper presents a beat classification method based on the time-series network, which integrates the interheartbeat rhythm information. This method is based on tree regularization constraints and the BiLSTM neural network model. This method improves the accuracy of heartbeat classification. And the interpretability of the proposed algorithm is analyzed by tree regularization constraints and feature analysis. The main contributions of this work are as follows:(1)
A time-series BiLSTM-Treg algorithm was designed to classify the beats, which combined the information of the beats so that the deep neural network could learn more rhythm information between heartbeats.(2)
A tree regularization method for the heartbeat classification model is proposed to optimize the BiLSTM-Treg algorithm and improve the generalization ability of the neural network model.(3)
By analyzing the key nodes of the simulated decision tree in tree regularization, the concerns in the learning process of the BiLSTM-Treg algorithm are analyzed, and the interpretability of the model is analyzed to a certain extent.(4)
Compared with other deep learning methods, the proposed BiLSTM-Treg algorithm improves the accuracy of heartbeat classification and reduces doctor’s misdiagnosis rate to a certain extent


## 2. Related Work

The diagnosis of early arrhythmia is mainly the doctor’s manual analysis of ECG waveform, which requires the doctor to have a professional medical theoretical basis and rich clinical experience. Because of the diversity of arrhythmia and the complexity of the ECG waveform, this method cannot meet the needs of patients. With the development of artificial intelligence, the classification of arrhythmia using intelligent processing technology has become a hot topic in recent years.In the 1950s, the automatic analysis technology of ECG signals has appeared in the field of ECG research. At first, only ECG filtering processing technology developed relatively mature. Later, with the continuous development of technology, automatic detection and diagnosis of arrhythmia disease also began to be continuously explored by researchers. In the past decades, domestic and foreign ECG researchers have proposed a variety of heartbeat classification methods. These methods can be divided into two categories from the perspective of whether manual feature extraction of ECG signals is needed: feature engineering-based classification methods and deep learning-based methods [5]. Traditional rule-based and machine-learning-based heartbeat classification methods both require manual feature extraction.


### 2.1. Heartbeat Classification Method Based on Feature Engineering

Feature engineering is to process a series of original data and extract the features as the input of the model to improve the performance of the model. Feature engineering mainly includes three aspects: feature selection, feature extraction, and feature construction. Feature extraction is the key step of ECG signal classification and recognition, and the extracted feature quality will affect the accuracy of ECG signal classification and recognition [6]. Generally, the features of ECG signals extracted by researchers mainly include morphological features [7], interphase features [8, 9], wavelet transform features [10], higher-order statistics (HOS) [9, 11], Hermite basis function (HBF) [12], QRS amplitude vector [13], and QRS composite wave area [14]. Then machine-learning algorithms are used for classification, such as the KNN algorithm [15], support vector machine (SVM) [7], and random forest [9]. Zhu et al. [7] extracted the ECG morphological features and used the SVM algorithm to classify the heartbeat, achieving a high classification accuracy. Yang et al. [9] extracted a variety of features, including RR interval, wavelet coefficient, and high-order statistics, and then used the random forest classifier based on an extreme learning machine to detect arrhythmias. Ji et al. [15] proposed a multifeature combination and stacked DWKNN algorithm to classify arrhythmias. The effects of different characteristic combinations on the classification of the heartbeat were analyzed.Although this method based on feature engineering can also achieve relatively high classification accuracy, because of the complex waveform and poor anti-interference ability of ECG signal, the features extracted by hand often produce the human error. And the features of the manual design are very dependent on the prior knowledge of the researcher. Deep learning has the advantage of automatically extracting features and classification, which well solves a series of problems caused by manual feature extraction.


### 2.2. Heartbeat Classification Method Based on Deep Learning

The deep learning model has become a common model for ECG data classification [16]. Compared with the feature engineering-based ECG classification method, the deep learning method, which uses original data rather than manually extracted features as input, can achieve better classification performance. In the deep learning method, researchers use the nonlinear transformation of hidden layers in the network to automatically obtain effective features and transform the original features into different new feature spaces by changing the structure of hidden layers in the network and the way of stacking [17], so as to make full use of the rich hidden information in the data and improve the classification accuracy.Recently, some researchers [18, 19] have used a deep neural network model for automatic classification of ECG signals. Ji et al. [20] proposed an ECG classification system based on Faster R-CNN. One-dimensional ECG signal is converted into two-dimensional image as the input of neural network to realize the classification of arrhythmias. Akarya et al. [21] proposed a 9-layer deep convolutional neural network (CNN) for automatic recognition of ECG signals. The original ECG signal and the ECG signal filtered out the high-frequency noise were used to classify the heartbeat, and the accuracy rates were 94.03% and 93.47%, respectively. Khan et al. [22] used the long short-term memory network (LSTM) to automatically identify 16 different types of arrhythmias. Wu et al. [23] proposed a heartbeat classification algorithm that integrated CNN and BiLSTM deep learning models and extracted the morphological and temporal features of heartbeat, respectively, by using CNN and BiLSTM. Li et al. [24] proposed a BiLSTM-Attention Network model to distinguish different types of arrhythmias. Pandey et al. [25] applied the extracted features of wavelet, RR interval, morphology, and high-order statistics to BiLSTM to achieve the automatic classification of the heartbeat. Yildirim et al. [26] proposed a heartbeat classification model based on wavelet transform and BiLSTM network, which used wavelet to decompose ECG signals into signals of different frequency scales and used the signals as the input sequence of the BiLSTM model.The classification method of ECG signals based on deep learning realizes the “end-to-end” learning mode, eliminates the manual design process of features, saves manpower, and makes the process of ECG classification simpler and more efficient. Although all the above studies cleverly used the deep neural network to classify ECG signals, the rhythm information between heartbeats has not been fully considered, the interpretability of the network has not been analyzed, and the classification accuracy needs to be improved.


## 2.1. Heartbeat Classification Method Based on Feature Engineering

Feature engineering is to process a series of original data and extract the features as the input of the model to improve the performance of the model. Feature engineering mainly includes three aspects: feature selection, feature extraction, and feature construction. Feature extraction is the key step of ECG signal classification and recognition, and the extracted feature quality will affect the accuracy of ECG signal classification and recognition [6]. Generally, the features of ECG signals extracted by researchers mainly include morphological features [7], interphase features [8, 9], wavelet transform features [10], higher-order statistics (HOS) [9, 11], Hermite basis function (HBF) [12], QRS amplitude vector [13], and QRS composite wave area [14]. Then machine-learning algorithms are used for classification, such as the KNN algorithm [15], support vector machine (SVM) [7], and random forest [9]. Zhu et al. [7] extracted the ECG morphological features and used the SVM algorithm to classify the heartbeat, achieving a high classification accuracy. Yang et al. [9] extracted a variety of features, including RR interval, wavelet coefficient, and high-order statistics, and then used the random forest classifier based on an extreme learning machine to detect arrhythmias. Ji et al. [15] proposed a multifeature combination and stacked DWKNN algorithm to classify arrhythmias. The effects of different characteristic combinations on the classification of the heartbeat were analyzed.Although this method based on feature engineering can also achieve relatively high classification accuracy, because of the complex waveform and poor anti-interference ability of ECG signal, the features extracted by hand often produce the human error. And the features of the manual design are very dependent on the prior knowledge of the researcher. Deep learning has the advantage of automatically extracting features and classification, which well solves a series of problems caused by manual feature extraction.


## 2.2. Heartbeat Classification Method Based on Deep Learning

The deep learning model has become a common model for ECG data classification [16]. Compared with the feature engineering-based ECG classification method, the deep learning method, which uses original data rather than manually extracted features as input, can achieve better classification performance. In the deep learning method, researchers use the nonlinear transformation of hidden layers in the network to automatically obtain effective features and transform the original features into different new feature spaces by changing the structure of hidden layers in the network and the way of stacking [17], so as to make full use of the rich hidden information in the data and improve the classification accuracy.Recently, some researchers [18, 19] have used a deep neural network model for automatic classification of ECG signals. Ji et al. [20] proposed an ECG classification system based on Faster R-CNN. One-dimensional ECG signal is converted into two-dimensional image as the input of neural network to realize the classification of arrhythmias. Akarya et al. [21] proposed a 9-layer deep convolutional neural network (CNN) for automatic recognition of ECG signals. The original ECG signal and the ECG signal filtered out the high-frequency noise were used to classify the heartbeat, and the accuracy rates were 94.03% and 93.47%, respectively. Khan et al. [22] used the long short-term memory network (LSTM) to automatically identify 16 different types of arrhythmias. Wu et al. [23] proposed a heartbeat classification algorithm that integrated CNN and BiLSTM deep learning models and extracted the morphological and temporal features of heartbeat, respectively, by using CNN and BiLSTM. Li et al. [24] proposed a BiLSTM-Attention Network model to distinguish different types of arrhythmias. Pandey et al. [25] applied the extracted features of wavelet, RR interval, morphology, and high-order statistics to BiLSTM to achieve the automatic classification of the heartbeat. Yildirim et al. [26] proposed a heartbeat classification model based on wavelet transform and BiLSTM network, which used wavelet to decompose ECG signals into signals of different frequency scales and used the signals as the input sequence of the BiLSTM model.The classification method of ECG signals based on deep learning realizes the “end-to-end” learning mode, eliminates the manual design process of features, saves manpower, and makes the process of ECG classification simpler and more efficient. Although all the above studies cleverly used the deep neural network to classify ECG signals, the rhythm information between heartbeats has not been fully considered, the interpretability of the network has not been analyzed, and the classification accuracy needs to be improved.


## 3. Method

The heartbeat classification method of the BiLSTM-Treg algorithm that integrates rhythm information between heartbeats proposed in this paper mainly includes the following steps: firstly, the data are preprocessed to filter out the noise in the ECG signal and segment ECG signal into heartbeats. Secondly, the continuous single heartbeat is combined into heartbeat segments so that the rhythm information between the heartbeats can be retained. Then, the BiLSTM-Treg model was constructed and optimized. Finally, the heartbeats were classified. Section3.1 is the preprocessing part, Section 3.2 is the representation of the rhythm information part, and Section 3.3 is the model building and optimization part.


### 3.1. ECG Signal Preprocessing

The preprocessing stage is mainly denoising and segmentation of ECG signals. Generally speaking, the collected ECG signals inevitably contain noise due to the influence of equipment and human body itself [27], which mainly includes baseline drift, power frequency interference, and EMG interference. It is important to remove as much noise as possible from ECG signals before classifying them. Wavelet transform is a generalization of short-time Fourier transform (STFT) [28], which can perform time-frequency analysis of ECG signals well. Compared with the equally spaced time-frequency localization of STFT, wavelet transform can provide higher frequency resolution at low frequency and higher time resolution at high frequency. In this paper, discrete wavelet transform is used to denoise ECG signals, which can avoid losing important physiological details in ECG signals and better retain the characteristics of ECG signals. Because of the high regularity of the Daubechies wavelet, the reconstructed signal is relatively smooth. And the strength spectrum of the DB6 wavelet [29, 30] is focused on low frequencies. Its moderate filter length and moderate coefficient values, compared with the other wavelets, provide more smoothing and less shift in the ECG fiducials. Therefore, in order to obtain a good classification accuracy, this paper uses the DB6 wavelet in the Daubechies wavelet base to process ECG signals. In terms of implementation, we use python’s open-source wavelet transform tool pywt. The discrete wavelet transform formula [31] is shown in (1) and (2).(1)WΨj,k=∑xfxΨj,kx,(2)Ψj,kx=a0−J/2Ψa0−jx−kb0,where WΨj,k is the wavelet coefficient, Ψj,kx is the discrete wavelet function at different scales and locations, fx is the input ECG signal, Ψk is the wavelet basis function, and j is the order of the scale. The larger j is, the smaller the scale is, which means the higher the frequency is and the closer it is to the details. k is the offset of position. a0 is the scale parameter and b0 is the position parameter. Signal comparison before and after pretreatment with discrete wavelet transform is shown in Figure 1 and Figure 2.Figure 1
The original ECG signal.Figure 2
The denoised ECG signal.Heartbeat segmentation is to divide an ECG record with a complete heartbeat as a unit [32]. A complete heartbeat should contain P wave, QRS compound wave, and T wave [33], as shown in Figure3(a). In this paper, the peak value of the R wave marked in the MIT-BIH database was used as the reference point for heartbeat segmentation, and 0.25s and 0.4s were extracted before and after the peak of R, as shown in Figure 3(b). We take this 0.65S data as a sample of a single heartbeat. For MIT-BIH ECG data with a sampling rate of 360HZ, we extracted 90 points before R peak and 144 points after R peak. Therefore, the reconstructed sample is 235 points.Figure 3
Morphology of a single heartbeat and heartbeat segmentation.
(a)(b)


### 3.2. Rhythm Information between Heartbeats

The rhythm information between heartbeats contained in the ECG is an important basis for doctors to diagnose heart diseases. Changes in ECG rhythm can reflect problems in different parts of the heart, which can help medical staff design more rational treatment plans. Common rhythm types are bigeminy, trigeminy, ventricular tachycardia, and atrial tachycardia.Bigeminy. Every normal heartbeat is followed by a premature beat. And the occurrence of three or more groups in a row is called bigeminy. According to the type of premature beat, it can be divided into ventricular bigeminy and atrial bigeminy. For example, the rhythm change of N–V–N–V–N–V is ventricular bigeminy, and the rhythm change of N–S–N–S–N–S is atrial bigeminy.Trigeminy. A premature beat occurs after every two normal heartbeats. And the occurrence of three or more groups in a row is called trigeminy. According to the type of premature beat, it can be divided into ventricular trigeminy and atrial trigeminy. For example, the rhythm change of N–N–V–N–N–V–N–N–V is ventricular trigeminy, and the rhythm change of N–N–S–N–N–S–N–N–S is atrial trigeminy. The ECG signal with ventricular trigeminy is shown in Figure 4.Figure 4
The ECG signal with ventricular trigeminy.Ventricular Tachycardia. Three or more consecutive ventricular premature beats are called ventricular tachycardia, such as the rhythm change V–V–V.Atrial Tachycardia. Three or more consecutive atrial premature beats are called atrial tachycardia, such as the rhythm change S–S–S.In addition, the appearance of certain types of heartbeats also reflects changes in ECG rhythm. For example, after a continuous ventricular tachycardia, a ventricular fusion heartbeat is often generated due to electrical signals from the sinus node, followed by ventricular capture. Therefore, ventricular fusion heartbeat and ventricular capture are important characteristics of ventricular tachycardia.In this paper, this rhythmic information, which is beneficial to the classification of heartbeats, was integrated into the model. Specifically, in processing the dataset, successive single beats were grouped into segments, which preserved information about rhythm between beats. Then, the ECG data is input into the neural network model in the unit of heartbeat segment, which enables the model to make full use of the rhythm information contained in the heartbeat segment when identifying the heartbeat type and improves the classification accuracy. The length of the heartbeat segment is one of the key points of our study.


### 3.3. BiLSTM-Treg Algorithm

Recurrent neural network (RNN) is a kind of neural network with short-term memory ability, which is very effective in processing data with sequence characteristics. However, in deep neural networks, the gradient is unstable. The gradient close to the input layer is calculated based on the product of the gradients of the subsequent layers [34]. When the neural network has too many hidden layers or the input sequence of the RNN network is too long, it will cause the gradient near the input layer to vanish or blow up, which affects the performance of RNN to some extent. In order to solve this problem, Hochreiter et al. [35] proposed the long short-term memory network (LSTM) in 1997. By adding gating units into RNN, the network can choose whether to retain the historical information so as to solve the problem of gradient disappearance and gradient explosion caused by long-term dependence of the RNN network.


#### 3.3.1. BiLSTM Neural Network Structure

Compared with RNN, LSTM adds three gating units, which are input gate, forgetting gate, and output gate. In addition, there are two important parts of LSTM, namely, memory unit, and hidden state. The forgetting gate controls whether the information in the memory unit is discarded, the input gate controls whether the information of the current signal and hidden state is added to the memory unit, and the output gate determines the information output in the memory unit. Figure5 shows the unit structure of the LSTM, where ft, it, and ot, respectively, represent the forgetting gate at the current moment, the input gate, and the output gate; Ct−1 and Ct, respectively, represent the state value of the memory unit at the previous moment and the current moment; ht−1 and ht, respectively, represent the hidden state at the previous moment and the current moment. xt represents the input at the current moment, and C˜t is the candidate value of the memory unit at the current moment. σ and tanh represent the sigmoid activation function and tanh activation function, respectively.Figure 5
The LSTM cell structure.The calculation process of LSTM can be expressed as equations (3–8):(3)it=sigmoidWixt+Uiht−1+bi,(4)ft=sigmoidWfxt+Ufht−1+bf,(5)ot=sigmoidWoxt+Uoht−1+bo,(6)C˜t=tanhWcxt+Ucht−1+bc,(7)Ct=ft⊗Ct−1+it⊗C˜t,(8)yt=ht=ot⊗tanhCt.Formulas (3)–(6), respectively, represent the calculation formulas for the input gate it, forget gate ft, output gate ot, and candidate value C˜t of the memory unit. They are all determined by the input data xt at the current moment, the hidden state ht−1 at the previous moment, and their corresponding weight matrix, where Wi, Wf, Wo, and Wc are the weight matrix of the current input xt; Ui, Uf, Uo, and Uc represent the weight matrix of the hidden state ht−1 at the last moment; bi, bf, bo, and bc are the corresponding bias items, respectively. These weight matrices and bias terms are trained by the way of gradient descent. Formula (7) indicates that the current moment memory unit Ct is adjusted by the current candidate unit C˜t and its own state Ct−1 as well as the input gate and the forgetting gate. Finally, formula (8) indicates that the output at the current moment, that is, the hidden state at the current moment, is determined by the current memory unit Ct and the output gate.One disadvantage of LSTM is that it cannot encode information upfront and can only use its past context, not its future context. In the classification of heartbeat, if the relevant information of the former and the latter can be obtained at the same time during the classification of the current heartbeat, the rhythm information of the heartbeat will be grasped more accurately, thus improving the classification accuracy of the current heartbeat. And BiLSTM solves this problem well [36]. In each BiLSTM layer, there are two independent LSTM to process sequences in two directions, respectively. The specific formula is shown in (9)–(11). At the time t, the hidden layer state Ht of BiLSTM obtains the heartbeat information ht⟶ before the time t through the forward LSTM and the heartbeat information ht⟵ after the time t through the backward LSTM and then carries out the weighted sum of ht⟶ and ht⟵, where Wt⟶ and Wt← are the corresponding weight matrices and bt is the bias term.(9)ht⟶=LSTMxt,ht−1⟶,(10)ht⟵=LSTMxt,ht−1⟵,(11)Ht=Wt⟶ht⟶+Wt⟵ht⟵+bt.


#### 3.3.2. BiLSTM Network Based on Tree Regularization

In machine learning, there are many strategies designed to reduce model generalization errors, which are collectively referred to as regularization. The form of regularization is very simple, which is to add an additional term after the objective function to affect the selection of the optimal point of the objective function. The common regularization methods are L1 regularization and L2 regularization. The common regularization methods are L1 regularization and L2 regularization. The objective function is shown in equation (12), where λΨW is a regular term.(12)minW∑n=1Nlossyn,yn^xn,W+λΨW.Tree regularization is a new regularization method proposed by Wu et al. [37], which can not only effectively improve the generalization ability of the model but also analyze the interpretability of the model. The tree regularization method of deep network model interpretability is a postinterpretable method, that is, the method of applying model analysis after model training to make the model interpretable. This method looks for the decision tree representation of the deep network model and realizes the human understanding of the prediction results of the network model by improving the human simulability of the network model. The implementation method of tree regularization includes the following two stages. First, we train deep neural network while being closely modeled by decision trees. In this way, this decision tree can accurately simulate the prediction process of the network. Secondly, the complexity metric of the decision tree, the average path length (APL), is taken as the penalty term for model optimization. In this way, the neural network can be encouraged to generate simple decision trees and restricted to generate complex decision trees, which further makes the generated decision trees easier to be simulated by human beings. The decision tree generation formula can be expressed by (13) and (14), where xn is the sample feature of the training set, yn^xn,W is the prediction label of the depth model, W is the weight matrix of the depth model, and ytn^ is the prediction label of the decision tree. The reason why yn^ is used as the input of the decision tree is to make ytn^ and yn^ as similar as possible so as to realize the purpose of using the decision tree to simulate the deep network.(13)Tree=Traintreexn,yn^xn,W,(14)ytn^=Tree.predictxn.The calculation formula of tree regularization is shown in (15), where PathLengthtree,xn is the path length of the n sample and ΩW is the average path length, namely, the penalty term.(15)ΩW=1N∑nPathLengthtree,xn.It can be seen from equation (15) that is not differentiable for network parameter W. Therefore, in order to use the gradient descent strategy in the network optimization process, Wu et al. [37] proposed the surrogate regularization function Ω˜W, which can surrogate the previous APL calculation method, as shown in equations (16) and (17). By training a Multilayer Perceptron (MLP), the mapping relationship between the parameter vector W of the neural network model and APL is established. With W and APL as inputs to MLP, the objective function of MLP is shown in equation (17), where ξ represents the weight matrix of the MLP model, ε represents the regularization intensity, Wj,ΩWj represents the known parameter vectors and their corresponding real APL datasets, and J represents the total number of datasets. Therefore, after using the surrogate model, the objective function of the BiLSTM network is shown in equation (18).(16)Ω˜W≈1N∑nPathLengthtree,xn,(17)minξ∑j=1JΩWj−Ω˜Wj,ξ2+εξ22,(18)minW∑n=1Nlossyn,yn^xn,W+λΩ˜W.In this paper, tree regularization is used in the BiLSTM model to optimize the model, reduce the generalization error of the model, and improve the classification accuracy. At the same time, the generated simulated decision tree is used to analyze and understand how the BiLSTM model carries out heartbeat classification. The BiLSTM model using tree regularization is shown in Figure6. Specifically, xt=xt1,xt2,…,xt235, is used to represent a single heartbeat sample. The heartbeat segment composed of consecutive single heartbeats is used as the input of the network, and the number of single heartbeats in the heartbeat segment t is the timestep of the network. The model first uses BiLSTM to classify heartbeat. Secondly, the decision tree is used to simulate BiLSTM, and APL is calculated. Then, the MLP model is trained to get the surrogate regularization function Ω˜W, and then Ω˜W is added to the objective function of the BiLSTM model for the next round of training. Algoithm 1 describes the BiLSTM-Treg model algorithm.Figure 6
The BiLSTM model based on tree regularization.Algorithm 1: The description of the BiLSTM-Treg model algorithm. BiLSTM-Treg model algorithm.
Input: dataset D=x1,y1,x2,y2,…,xn,ynOutput: classification results and model parametersProcess:(1)
Build the BiLSTM-Treg model(2)
While training,(3)
Train the network according to formula (18)(4)
Get the forecast resultsyn^ for the current round(5)
Usexn,yn^ to train the decision tree(6)
Calculate the average path length of the decision tree(7)
Train MLP model to obtainΩ˜W(8)
Update theΩ˜W formula (18)(9)
If training loss stop decreasing, then(10)
Store the model and break(11)
End(12)
End


## 3.1. ECG Signal Preprocessing

The preprocessing stage is mainly denoising and segmentation of ECG signals. Generally speaking, the collected ECG signals inevitably contain noise due to the influence of equipment and human body itself [27], which mainly includes baseline drift, power frequency interference, and EMG interference. It is important to remove as much noise as possible from ECG signals before classifying them. Wavelet transform is a generalization of short-time Fourier transform (STFT) [28], which can perform time-frequency analysis of ECG signals well. Compared with the equally spaced time-frequency localization of STFT, wavelet transform can provide higher frequency resolution at low frequency and higher time resolution at high frequency. In this paper, discrete wavelet transform is used to denoise ECG signals, which can avoid losing important physiological details in ECG signals and better retain the characteristics of ECG signals. Because of the high regularity of the Daubechies wavelet, the reconstructed signal is relatively smooth. And the strength spectrum of the DB6 wavelet [29, 30] is focused on low frequencies. Its moderate filter length and moderate coefficient values, compared with the other wavelets, provide more smoothing and less shift in the ECG fiducials. Therefore, in order to obtain a good classification accuracy, this paper uses the DB6 wavelet in the Daubechies wavelet base to process ECG signals. In terms of implementation, we use python’s open-source wavelet transform tool pywt. The discrete wavelet transform formula [31] is shown in (1) and (2).(1)WΨj,k=∑xfxΨj,kx,(2)Ψj,kx=a0−J/2Ψa0−jx−kb0,where WΨj,k is the wavelet coefficient, Ψj,kx is the discrete wavelet function at different scales and locations, fx is the input ECG signal, Ψk is the wavelet basis function, and j is the order of the scale. The larger j is, the smaller the scale is, which means the higher the frequency is and the closer it is to the details. k is the offset of position. a0 is the scale parameter and b0 is the position parameter. Signal comparison before and after pretreatment with discrete wavelet transform is shown in Figure 1 and Figure 2.Figure 1
The original ECG signal.Figure 2
The denoised ECG signal.Heartbeat segmentation is to divide an ECG record with a complete heartbeat as a unit [32]. A complete heartbeat should contain P wave, QRS compound wave, and T wave [33], as shown in Figure3(a). In this paper, the peak value of the R wave marked in the MIT-BIH database was used as the reference point for heartbeat segmentation, and 0.25s and 0.4s were extracted before and after the peak of R, as shown in Figure 3(b). We take this 0.65S data as a sample of a single heartbeat. For MIT-BIH ECG data with a sampling rate of 360HZ, we extracted 90 points before R peak and 144 points after R peak. Therefore, the reconstructed sample is 235 points.Figure 3
Morphology of a single heartbeat and heartbeat segmentation.
(a)(b)


## 3.2. Rhythm Information between Heartbeats

The rhythm information between heartbeats contained in the ECG is an important basis for doctors to diagnose heart diseases. Changes in ECG rhythm can reflect problems in different parts of the heart, which can help medical staff design more rational treatment plans. Common rhythm types are bigeminy, trigeminy, ventricular tachycardia, and atrial tachycardia.Bigeminy. Every normal heartbeat is followed by a premature beat. And the occurrence of three or more groups in a row is called bigeminy. According to the type of premature beat, it can be divided into ventricular bigeminy and atrial bigeminy. For example, the rhythm change of N–V–N–V–N–V is ventricular bigeminy, and the rhythm change of N–S–N–S–N–S is atrial bigeminy.Trigeminy. A premature beat occurs after every two normal heartbeats. And the occurrence of three or more groups in a row is called trigeminy. According to the type of premature beat, it can be divided into ventricular trigeminy and atrial trigeminy. For example, the rhythm change of N–N–V–N–N–V–N–N–V is ventricular trigeminy, and the rhythm change of N–N–S–N–N–S–N–N–S is atrial trigeminy. The ECG signal with ventricular trigeminy is shown in Figure 4.Figure 4
The ECG signal with ventricular trigeminy.Ventricular Tachycardia. Three or more consecutive ventricular premature beats are called ventricular tachycardia, such as the rhythm change V–V–V.Atrial Tachycardia. Three or more consecutive atrial premature beats are called atrial tachycardia, such as the rhythm change S–S–S.In addition, the appearance of certain types of heartbeats also reflects changes in ECG rhythm. For example, after a continuous ventricular tachycardia, a ventricular fusion heartbeat is often generated due to electrical signals from the sinus node, followed by ventricular capture. Therefore, ventricular fusion heartbeat and ventricular capture are important characteristics of ventricular tachycardia.In this paper, this rhythmic information, which is beneficial to the classification of heartbeats, was integrated into the model. Specifically, in processing the dataset, successive single beats were grouped into segments, which preserved information about rhythm between beats. Then, the ECG data is input into the neural network model in the unit of heartbeat segment, which enables the model to make full use of the rhythm information contained in the heartbeat segment when identifying the heartbeat type and improves the classification accuracy. The length of the heartbeat segment is one of the key points of our study.


## 3.3. BiLSTM-Treg Algorithm

Recurrent neural network (RNN) is a kind of neural network with short-term memory ability, which is very effective in processing data with sequence characteristics. However, in deep neural networks, the gradient is unstable. The gradient close to the input layer is calculated based on the product of the gradients of the subsequent layers [34]. When the neural network has too many hidden layers or the input sequence of the RNN network is too long, it will cause the gradient near the input layer to vanish or blow up, which affects the performance of RNN to some extent. In order to solve this problem, Hochreiter et al. [35] proposed the long short-term memory network (LSTM) in 1997. By adding gating units into RNN, the network can choose whether to retain the historical information so as to solve the problem of gradient disappearance and gradient explosion caused by long-term dependence of the RNN network.


### 3.3.1. BiLSTM Neural Network Structure

Compared with RNN, LSTM adds three gating units, which are input gate, forgetting gate, and output gate. In addition, there are two important parts of LSTM, namely, memory unit, and hidden state. The forgetting gate controls whether the information in the memory unit is discarded, the input gate controls whether the information of the current signal and hidden state is added to the memory unit, and the output gate determines the information output in the memory unit. Figure5 shows the unit structure of the LSTM, where ft, it, and ot, respectively, represent the forgetting gate at the current moment, the input gate, and the output gate; Ct−1 and Ct, respectively, represent the state value of the memory unit at the previous moment and the current moment; ht−1 and ht, respectively, represent the hidden state at the previous moment and the current moment. xt represents the input at the current moment, and C˜t is the candidate value of the memory unit at the current moment. σ and tanh represent the sigmoid activation function and tanh activation function, respectively.Figure 5
The LSTM cell structure.The calculation process of LSTM can be expressed as equations (3–8):(3)it=sigmoidWixt+Uiht−1+bi,(4)ft=sigmoidWfxt+Ufht−1+bf,(5)ot=sigmoidWoxt+Uoht−1+bo,(6)C˜t=tanhWcxt+Ucht−1+bc,(7)Ct=ft⊗Ct−1+it⊗C˜t,(8)yt=ht=ot⊗tanhCt.Formulas (3)–(6), respectively, represent the calculation formulas for the input gate it, forget gate ft, output gate ot, and candidate value C˜t of the memory unit. They are all determined by the input data xt at the current moment, the hidden state ht−1 at the previous moment, and their corresponding weight matrix, where Wi, Wf, Wo, and Wc are the weight matrix of the current input xt; Ui, Uf, Uo, and Uc represent the weight matrix of the hidden state ht−1 at the last moment; bi, bf, bo, and bc are the corresponding bias items, respectively. These weight matrices and bias terms are trained by the way of gradient descent. Formula (7) indicates that the current moment memory unit Ct is adjusted by the current candidate unit C˜t and its own state Ct−1 as well as the input gate and the forgetting gate. Finally, formula (8) indicates that the output at the current moment, that is, the hidden state at the current moment, is determined by the current memory unit Ct and the output gate.One disadvantage of LSTM is that it cannot encode information upfront and can only use its past context, not its future context. In the classification of heartbeat, if the relevant information of the former and the latter can be obtained at the same time during the classification of the current heartbeat, the rhythm information of the heartbeat will be grasped more accurately, thus improving the classification accuracy of the current heartbeat. And BiLSTM solves this problem well [36]. In each BiLSTM layer, there are two independent LSTM to process sequences in two directions, respectively. The specific formula is shown in (9)–(11). At the time t, the hidden layer state Ht of BiLSTM obtains the heartbeat information ht⟶ before the time t through the forward LSTM and the heartbeat information ht⟵ after the time t through the backward LSTM and then carries out the weighted sum of ht⟶ and ht⟵, where Wt⟶ and Wt← are the corresponding weight matrices and bt is the bias term.(9)ht⟶=LSTMxt,ht−1⟶,(10)ht⟵=LSTMxt,ht−1⟵,(11)Ht=Wt⟶ht⟶+Wt⟵ht⟵+bt.


### 3.3.2. BiLSTM Network Based on Tree Regularization

In machine learning, there are many strategies designed to reduce model generalization errors, which are collectively referred to as regularization. The form of regularization is very simple, which is to add an additional term after the objective function to affect the selection of the optimal point of the objective function. The common regularization methods are L1 regularization and L2 regularization. The common regularization methods are L1 regularization and L2 regularization. The objective function is shown in equation (12), where λΨW is a regular term.(12)minW∑n=1Nlossyn,yn^xn,W+λΨW.Tree regularization is a new regularization method proposed by Wu et al. [37], which can not only effectively improve the generalization ability of the model but also analyze the interpretability of the model. The tree regularization method of deep network model interpretability is a postinterpretable method, that is, the method of applying model analysis after model training to make the model interpretable. This method looks for the decision tree representation of the deep network model and realizes the human understanding of the prediction results of the network model by improving the human simulability of the network model. The implementation method of tree regularization includes the following two stages. First, we train deep neural network while being closely modeled by decision trees. In this way, this decision tree can accurately simulate the prediction process of the network. Secondly, the complexity metric of the decision tree, the average path length (APL), is taken as the penalty term for model optimization. In this way, the neural network can be encouraged to generate simple decision trees and restricted to generate complex decision trees, which further makes the generated decision trees easier to be simulated by human beings. The decision tree generation formula can be expressed by (13) and (14), where xn is the sample feature of the training set, yn^xn,W is the prediction label of the depth model, W is the weight matrix of the depth model, and ytn^ is the prediction label of the decision tree. The reason why yn^ is used as the input of the decision tree is to make ytn^ and yn^ as similar as possible so as to realize the purpose of using the decision tree to simulate the deep network.(13)Tree=Traintreexn,yn^xn,W,(14)ytn^=Tree.predictxn.The calculation formula of tree regularization is shown in (15), where PathLengthtree,xn is the path length of the n sample and ΩW is the average path length, namely, the penalty term.(15)ΩW=1N∑nPathLengthtree,xn.It can be seen from equation (15) that is not differentiable for network parameter W. Therefore, in order to use the gradient descent strategy in the network optimization process, Wu et al. [37] proposed the surrogate regularization function Ω˜W, which can surrogate the previous APL calculation method, as shown in equations (16) and (17). By training a Multilayer Perceptron (MLP), the mapping relationship between the parameter vector W of the neural network model and APL is established. With W and APL as inputs to MLP, the objective function of MLP is shown in equation (17), where ξ represents the weight matrix of the MLP model, ε represents the regularization intensity, Wj,ΩWj represents the known parameter vectors and their corresponding real APL datasets, and J represents the total number of datasets. Therefore, after using the surrogate model, the objective function of the BiLSTM network is shown in equation (18).(16)Ω˜W≈1N∑nPathLengthtree,xn,(17)minξ∑j=1JΩWj−Ω˜Wj,ξ2+εξ22,(18)minW∑n=1Nlossyn,yn^xn,W+λΩ˜W.In this paper, tree regularization is used in the BiLSTM model to optimize the model, reduce the generalization error of the model, and improve the classification accuracy. At the same time, the generated simulated decision tree is used to analyze and understand how the BiLSTM model carries out heartbeat classification. The BiLSTM model using tree regularization is shown in Figure6. Specifically, xt=xt1,xt2,…,xt235, is used to represent a single heartbeat sample. The heartbeat segment composed of consecutive single heartbeats is used as the input of the network, and the number of single heartbeats in the heartbeat segment t is the timestep of the network. The model first uses BiLSTM to classify heartbeat. Secondly, the decision tree is used to simulate BiLSTM, and APL is calculated. Then, the MLP model is trained to get the surrogate regularization function Ω˜W, and then Ω˜W is added to the objective function of the BiLSTM model for the next round of training. Algoithm 1 describes the BiLSTM-Treg model algorithm.Figure 6
The BiLSTM model based on tree regularization.Algorithm 1: The description of the BiLSTM-Treg model algorithm. BiLSTM-Treg model algorithm.
Input: dataset D=x1,y1,x2,y2,…,xn,ynOutput: classification results and model parametersProcess:(1)
Build the BiLSTM-Treg model(2)
While training,(3)
Train the network according to formula (18)(4)
Get the forecast resultsyn^ for the current round(5)
Usexn,yn^ to train the decision tree(6)
Calculate the average path length of the decision tree(7)
Train MLP model to obtainΩ˜W(8)
Update theΩ˜W formula (18)(9)
If training loss stop decreasing, then(10)
Store the model and break(11)
End(12)
End


## 3.3.1. BiLSTM Neural Network Structure

Compared with RNN, LSTM adds three gating units, which are input gate, forgetting gate, and output gate. In addition, there are two important parts of LSTM, namely, memory unit, and hidden state. The forgetting gate controls whether the information in the memory unit is discarded, the input gate controls whether the information of the current signal and hidden state is added to the memory unit, and the output gate determines the information output in the memory unit. Figure5 shows the unit structure of the LSTM, where ft, it, and ot, respectively, represent the forgetting gate at the current moment, the input gate, and the output gate; Ct−1 and Ct, respectively, represent the state value of the memory unit at the previous moment and the current moment; ht−1 and ht, respectively, represent the hidden state at the previous moment and the current moment. xt represents the input at the current moment, and C˜t is the candidate value of the memory unit at the current moment. σ and tanh represent the sigmoid activation function and tanh activation function, respectively.Figure 5
The LSTM cell structure.The calculation process of LSTM can be expressed as equations (3–8):(3)it=sigmoidWixt+Uiht−1+bi,(4)ft=sigmoidWfxt+Ufht−1+bf,(5)ot=sigmoidWoxt+Uoht−1+bo,(6)C˜t=tanhWcxt+Ucht−1+bc,(7)Ct=ft⊗Ct−1+it⊗C˜t,(8)yt=ht=ot⊗tanhCt.Formulas (3)–(6), respectively, represent the calculation formulas for the input gate it, forget gate ft, output gate ot, and candidate value C˜t of the memory unit. They are all determined by the input data xt at the current moment, the hidden state ht−1 at the previous moment, and their corresponding weight matrix, where Wi, Wf, Wo, and Wc are the weight matrix of the current input xt; Ui, Uf, Uo, and Uc represent the weight matrix of the hidden state ht−1 at the last moment; bi, bf, bo, and bc are the corresponding bias items, respectively. These weight matrices and bias terms are trained by the way of gradient descent. Formula (7) indicates that the current moment memory unit Ct is adjusted by the current candidate unit C˜t and its own state Ct−1 as well as the input gate and the forgetting gate. Finally, formula (8) indicates that the output at the current moment, that is, the hidden state at the current moment, is determined by the current memory unit Ct and the output gate.One disadvantage of LSTM is that it cannot encode information upfront and can only use its past context, not its future context. In the classification of heartbeat, if the relevant information of the former and the latter can be obtained at the same time during the classification of the current heartbeat, the rhythm information of the heartbeat will be grasped more accurately, thus improving the classification accuracy of the current heartbeat. And BiLSTM solves this problem well [36]. In each BiLSTM layer, there are two independent LSTM to process sequences in two directions, respectively. The specific formula is shown in (9)–(11). At the time t, the hidden layer state Ht of BiLSTM obtains the heartbeat information ht⟶ before the time t through the forward LSTM and the heartbeat information ht⟵ after the time t through the backward LSTM and then carries out the weighted sum of ht⟶ and ht⟵, where Wt⟶ and Wt← are the corresponding weight matrices and bt is the bias term.(9)ht⟶=LSTMxt,ht−1⟶,(10)ht⟵=LSTMxt,ht−1⟵,(11)Ht=Wt⟶ht⟶+Wt⟵ht⟵+bt.


## 3.3.2. BiLSTM Network Based on Tree Regularization

In machine learning, there are many strategies designed to reduce model generalization errors, which are collectively referred to as regularization. The form of regularization is very simple, which is to add an additional term after the objective function to affect the selection of the optimal point of the objective function. The common regularization methods are L1 regularization and L2 regularization. The common regularization methods are L1 regularization and L2 regularization. The objective function is shown in equation (12), where λΨW is a regular term.(12)minW∑n=1Nlossyn,yn^xn,W+λΨW.Tree regularization is a new regularization method proposed by Wu et al. [37], which can not only effectively improve the generalization ability of the model but also analyze the interpretability of the model. The tree regularization method of deep network model interpretability is a postinterpretable method, that is, the method of applying model analysis after model training to make the model interpretable. This method looks for the decision tree representation of the deep network model and realizes the human understanding of the prediction results of the network model by improving the human simulability of the network model. The implementation method of tree regularization includes the following two stages. First, we train deep neural network while being closely modeled by decision trees. In this way, this decision tree can accurately simulate the prediction process of the network. Secondly, the complexity metric of the decision tree, the average path length (APL), is taken as the penalty term for model optimization. In this way, the neural network can be encouraged to generate simple decision trees and restricted to generate complex decision trees, which further makes the generated decision trees easier to be simulated by human beings. The decision tree generation formula can be expressed by (13) and (14), where xn is the sample feature of the training set, yn^xn,W is the prediction label of the depth model, W is the weight matrix of the depth model, and ytn^ is the prediction label of the decision tree. The reason why yn^ is used as the input of the decision tree is to make ytn^ and yn^ as similar as possible so as to realize the purpose of using the decision tree to simulate the deep network.(13)Tree=Traintreexn,yn^xn,W,(14)ytn^=Tree.predictxn.The calculation formula of tree regularization is shown in (15), where PathLengthtree,xn is the path length of the n sample and ΩW is the average path length, namely, the penalty term.(15)ΩW=1N∑nPathLengthtree,xn.It can be seen from equation (15) that is not differentiable for network parameter W. Therefore, in order to use the gradient descent strategy in the network optimization process, Wu et al. [37] proposed the surrogate regularization function Ω˜W, which can surrogate the previous APL calculation method, as shown in equations (16) and (17). By training a Multilayer Perceptron (MLP), the mapping relationship between the parameter vector W of the neural network model and APL is established. With W and APL as inputs to MLP, the objective function of MLP is shown in equation (17), where ξ represents the weight matrix of the MLP model, ε represents the regularization intensity, Wj,ΩWj represents the known parameter vectors and their corresponding real APL datasets, and J represents the total number of datasets. Therefore, after using the surrogate model, the objective function of the BiLSTM network is shown in equation (18).(16)Ω˜W≈1N∑nPathLengthtree,xn,(17)minξ∑j=1JΩWj−Ω˜Wj,ξ2+εξ22,(18)minW∑n=1Nlossyn,yn^xn,W+λΩ˜W.In this paper, tree regularization is used in the BiLSTM model to optimize the model, reduce the generalization error of the model, and improve the classification accuracy. At the same time, the generated simulated decision tree is used to analyze and understand how the BiLSTM model carries out heartbeat classification. The BiLSTM model using tree regularization is shown in Figure6. Specifically, xt=xt1,xt2,…,xt235, is used to represent a single heartbeat sample. The heartbeat segment composed of consecutive single heartbeats is used as the input of the network, and the number of single heartbeats in the heartbeat segment t is the timestep of the network. The model first uses BiLSTM to classify heartbeat. Secondly, the decision tree is used to simulate BiLSTM, and APL is calculated. Then, the MLP model is trained to get the surrogate regularization function Ω˜W, and then Ω˜W is added to the objective function of the BiLSTM model for the next round of training. Algoithm 1 describes the BiLSTM-Treg model algorithm.Figure 6
The BiLSTM model based on tree regularization.Algorithm 1: The description of the BiLSTM-Treg model algorithm. BiLSTM-Treg model algorithm.
Input: dataset D=x1,y1,x2,y2,…,xn,ynOutput: classification results and model parametersProcess:(1)
Build the BiLSTM-Treg model(2)
While training,(3)
Train the network according to formula (18)(4)
Get the forecast resultsyn^ for the current round(5)
Usexn,yn^ to train the decision tree(6)
Calculate the average path length of the decision tree(7)
Train MLP model to obtainΩ˜W(8)
Update theΩ˜W formula (18)(9)
If training loss stop decreasing, then(10)
Store the model and break(11)
End(12)
End


## 4. Experiment

The processing and analysis of ECG signal is very important to the classification of the heartbeat. The research focus of this paper is on the construction and optimization of the model integrating rhythm information. According to the ANSI/AAMI EC57:2012 classification proposed by the Association for the Advancement of Medical Instruments (AAMI), arrhythmia can be divided into five categories: N (normal or bundle branch block), S (supraventricular ectopic beat), V (ventricular ectopic beat), F (fusion beat), andQ (beat not specified). On the basis of extracting continuous heartbeat segments, this experiment constructs a time-series network that integrates rhythm information between heartbeats and divides heartbeats into the above five types.


### 4.1. Experimental Environment

The model proposed in this paper is trained and tested on a PC workstation with Xeon(R)Silver-4114CPU, 32 GB memory, and Geforce2080Ti graphics card. The PC workstation runs on Ubuntu 18.04 system. And the algorithm is run under the TensorFlow-GPU V2.2.0 framework.


### 4.2. Experimental Data

A unified and authoritative standard database is the basis of the automatic analysis of ECG signals. In the research field of ECG signals, the MIT-BIH arrhythmia database is the most widely used database by researchers [38]. The database contains 48 records, each of which is about 30 minutes long, with about 650,000 sampling points and a sampling frequency of 360 Hz. Fifteen categories were labeled in the MIT-BIH arrhythmia database. Table 1 is the corresponding table of the two heartbeat classification methods.Table 1
Correspondence between MIT-BIH arrhythmia database annotations and AAMI heartbeat types.
AAMI heartbeat categoryMIT-BIH heartbeat typesNNormal beat (N); left bundle branch block beat (L); right bundle branch block beat (R); nodal (junctional) escape beat (j); atrial escape beat (e)SAberrated atrial premature beat (a); nodal (junctional) premature beat (J); atrial premature beat (A); premature or ectopic supraventricular beat (S)VPremature ventricular contraction (V); ventricular escape beat (E)FFusion of ventricular and normal beat (F)QPaced beat (/); unclassifiable beat (Q); fusion of paced and normal beat (f)In this paper, we classified 109,454 heartbeats from the MIT-BIH arrhythmia database, including 90,595 N-type heartbeats; 2,781 heartbeats in the S category; 7,235 V-type heartbeats. The number of heartbeats in category F was only 802 and inQ was 8041. In this paper, 90% of the heartbeat data were randomly selected from the dataset as the training set and the remaining 10% as the test set. And the specific distribution of data is shown in Table 2.Table 2
Experimental data statistics.
Training setTesting setTotalN81,5519,04490,595S2,5012802,781V6,5197167,235F72379802Q7,2427998041


### 4.3. Evaluation Metrics

In order to calculate the performance of the model for heartbeat classification, the classification results were divided into four categories: TP, FP, TN, and FN. Take N-type as an example; formulas (19)–(22), respectively, represent the calculation methods of type N true positive heartbeat (TPN), type N false-positive heartbeat (FPN), type N true negative heartbeat (TNN), and type N false-negative heartbeat (FNN). Table 3 shows the confusion matrix of the classification results.Table 3
Classification results of heartbeat statistics.
Reference labelsPredicted labelsnsvfqNNnNsNvNfNqSSnSsSvSfSqVVnVsVvVfVqFFnFsFvFfFqQQnQsQvQfQq(19)TPN=Nn,(20)FPN=Sn+Vn+Fn+Qn,(21)TNN=Ss+Sv+Sf+Sq+Vs+Vv+Vf+Vq+Fs+Fv+Ff+Fq+Qs+Qv+Qf+Qq,(22)FNN=Ns+Nv+Nf+Nq.In this paper, sensitivity, specificity, positive predictive value, and accuracy are used as indicators of classifier performance. Sensitivity (Se), also known as recall rate, is the proportion of positive samples that are correctly judged to be positive. The higher the sensitivity, the greater the proportion of samples correctly predicted. Specificity (Sp) is the proportion of correctly judged negative samples to actually negative samples. The positive predictive value (+p) refers to the proportion of correctly judged positive samples to all the judged positive samples. Accuracy (Acc) is the ratio of the sum of true positives and true negatives to the total number of samples, reflecting the consistency between test results and actual results. The calculation formula of the above four evaluation metrics is shown in (23–26).(23)Se=TPTP+FN,(24)Sp=TNTN+FP,(25)+p=TPTP+FP,(26)Acc=TP+TNTP+TN+FP+FN.


## 4.1. Experimental Environment

The model proposed in this paper is trained and tested on a PC workstation with Xeon(R)Silver-4114CPU, 32 GB memory, and Geforce2080Ti graphics card. The PC workstation runs on Ubuntu 18.04 system. And the algorithm is run under the TensorFlow-GPU V2.2.0 framework.


## 4.2. Experimental Data

A unified and authoritative standard database is the basis of the automatic analysis of ECG signals. In the research field of ECG signals, the MIT-BIH arrhythmia database is the most widely used database by researchers [38]. The database contains 48 records, each of which is about 30 minutes long, with about 650,000 sampling points and a sampling frequency of 360 Hz. Fifteen categories were labeled in the MIT-BIH arrhythmia database. Table 1 is the corresponding table of the two heartbeat classification methods.Table 1
Correspondence between MIT-BIH arrhythmia database annotations and AAMI heartbeat types.
AAMI heartbeat categoryMIT-BIH heartbeat typesNNormal beat (N); left bundle branch block beat (L); right bundle branch block beat (R); nodal (junctional) escape beat (j); atrial escape beat (e)SAberrated atrial premature beat (a); nodal (junctional) premature beat (J); atrial premature beat (A); premature or ectopic supraventricular beat (S)VPremature ventricular contraction (V); ventricular escape beat (E)FFusion of ventricular and normal beat (F)QPaced beat (/); unclassifiable beat (Q); fusion of paced and normal beat (f)In this paper, we classified 109,454 heartbeats from the MIT-BIH arrhythmia database, including 90,595 N-type heartbeats; 2,781 heartbeats in the S category; 7,235 V-type heartbeats. The number of heartbeats in category F was only 802 and inQ was 8041. In this paper, 90% of the heartbeat data were randomly selected from the dataset as the training set and the remaining 10% as the test set. And the specific distribution of data is shown in Table 2.Table 2
Experimental data statistics.
Training setTesting setTotalN81,5519,04490,595S2,5012802,781V6,5197167,235F72379802Q7,2427998041


## 4.3. Evaluation Metrics

In order to calculate the performance of the model for heartbeat classification, the classification results were divided into four categories: TP, FP, TN, and FN. Take N-type as an example; formulas (19)–(22), respectively, represent the calculation methods of type N true positive heartbeat (TPN), type N false-positive heartbeat (FPN), type N true negative heartbeat (TNN), and type N false-negative heartbeat (FNN). Table 3 shows the confusion matrix of the classification results.Table 3
Classification results of heartbeat statistics.
Reference labelsPredicted labelsnsvfqNNnNsNvNfNqSSnSsSvSfSqVVnVsVvVfVqFFnFsFvFfFqQQnQsQvQfQq(19)TPN=Nn,(20)FPN=Sn+Vn+Fn+Qn,(21)TNN=Ss+Sv+Sf+Sq+Vs+Vv+Vf+Vq+Fs+Fv+Ff+Fq+Qs+Qv+Qf+Qq,(22)FNN=Ns+Nv+Nf+Nq.In this paper, sensitivity, specificity, positive predictive value, and accuracy are used as indicators of classifier performance. Sensitivity (Se), also known as recall rate, is the proportion of positive samples that are correctly judged to be positive. The higher the sensitivity, the greater the proportion of samples correctly predicted. Specificity (Sp) is the proportion of correctly judged negative samples to actually negative samples. The positive predictive value (+p) refers to the proportion of correctly judged positive samples to all the judged positive samples. Accuracy (Acc) is the ratio of the sum of true positives and true negatives to the total number of samples, reflecting the consistency between test results and actual results. The calculation formula of the above four evaluation metrics is shown in (23–26).(23)Se=TPTP+FN,(24)Sp=TNTN+FP,(25)+p=TPTP+FP,(26)Acc=TP+TNTP+TN+FP+FN.


## 5. Results and Analysis

In order to build a time-series network model that is most suitable for the task of heartbeat classification and more accurately distinguish the categories of arrhythmias, we conducted the following five groups of experiments. In this section, we first compare and analyze the performance of RNN, GRU, and LSTM in heartbeat classification (Section5.1). Secondly, the network is changed to bidirectional, and the classification results of BiRNN, BiGRU, and BiLSTM are compared (Section 5.2). Thirdly, by comparing the effects of different heartbeat lengths on the classification performance of the BiLSTM model, the optimal heartbeat length was selected (Section 5.3). Then, tree regularization was used to optimize the BiLSTM model. By adding tree regularization, the generalization ability of BiLSTM is improved, and the classification accuracy is improved, compared with the traditional L1 and L2 regularization (Section 5.4). Then, the important features of the simulated decision tree are analyzed and verified by experiments (Section 5.5). Finally, the results are compared with other references (Section 5.6).


### 5.1. Analysis of Experimental Results of Different Time-Series Networks

In order to select the optimal time-series network model, Experiment 1 selected three network models, namely, RNN, GRU, and LSTM, for heartbeat classification. The experimental results show that the overall classification accuracy of the RNN model and GRU model is 98.98% and 98.97%, respectively. The overall classification accuracy of the LSTM model is 99.09%, which is better than that of the RNN model and GRU model. However, it cannot fully consider the rhythm information by using the one-way recurrent neural network for heartbeat classification. Table4 shows the classification results and performance of three one-way recurrent neural networks.Table 4
Comparison of the classification results of RNN, GRU, and LSTM network models.
RNNGRULSTMSe (%)Sp (%)+p (%)Acc (%)Se (%)Sp (%)+p (%)Acc (%)Se (%)Sp (%)+p (%)Acc (%)N99.6197.1099.3599.1599.4597.8099.5199.1599.6997.4099.4299.27S90.4099.8092.8699.5492.7299.7792.1199.5892.0599.9096.1999.68V97.6699.8097.2699.6697.9499.7696.6199.6396.9899.7796.8499.59F71.2699.9491.1899.7271.2699.9186.1199.6875.8699.9186.8499.72Q99.4399.9499.3299.9099.7799.9098.8899.8999.5599.9799.6699.94


### 5.2. Analysis of Experimental Results of Different Bidirectional Time-Series Networks

The one-way recurrent neural network can only learn the heartbeat information before the current moment when performing heartbeat classification. Therefore, we improve the selected LSTM network to BiLSTM so that the network can consider both the previous heartbeat information and the future heartbeat information. And the BiRNN and BiGRU networks are used for comparison and verification. The experimental results show that the overall classification accuracy of the BiRNN model and BiGRU model is 99.13% and 98.92%, respectively. The overall classification accuracy of the BiLSTM model is 99.18%, which is better than that of the BiRNN model and BiGRU model. Table5 shows the classification results and performance of the three bidirectional recurrent neural networks.Table 5
Comparison of the classification results of BiRNN, BiGRU, and BiLSTM network models.
BiRNNBiGRUBiLSTMSe (%)Sp (%)+p (%)Acc (%)Se (%)Sp (%)+p (%)Acc (%)Se (%)Sp (%)+p (%)Acc (%)N99.6597.6599.4799.2999.6297.0599.3499.1599.6498.1599.5999.37S90.4099.8193.1799.5589.0799.8293.4099.5292.7299.8393.9699.63V98.2199.8397.6899.7397.1299.8097.2599.6398.6399.7696.6499.68F74.7199.9389.0499.7367.8299.9084.2999.6470.1199.9388.4199.69Q100.0099.9799.6699.9799.7799.9198.9999.90100.0099.9899.7799.98


### 5.3. Select the Optimal Length of Heartbeat Segment

In order to select the optimal length of the heartbeat segment, a total of 7 experiments were conducted. The length of heartbeat segments selected by us is 1, 5, 10, 15, 20, 25, and 30, respectively, and the corresponding timestep of the BiLSTM is also 1, 5, 10, 15, 20, 25, and 30, respectively. The experimental results show that the classification accuracy of the network is gradually improved when the length of the heartbeat segment is less than 15. However, when the length of the heartbeat is greater than 15, the classification performance of the network decreases rapidly. The main reason is that the rhythm information of heartbeat, such as bigeminy, trigeminy, atrial tachycardia, and ventricular tachycardia, can be shown within 15 beats. When the heartbeat segment is too long, the heartbeat information considered by the network is too redundant, which will affect the network performance. Table6 shows the classification results of the BiLSTM network with different lengths of heartbeat segments.Table 6
Effects of heartbeat segments of different lengths on the classification results of BiLSTM model.
Time step151015202530Overall accuracy (%)99.0499.0299.1299.1898.5582.5284.53


### 5.4. Analyze the Experimental Results of Different Regularization Methods

In order to improve the generalization ability of BiLSTM and further improve the classification accuracy, we choose tree regularization to constrain the weight of the network and use the traditional L1 and L2 regularization for comparison. Experimental results verify the feasibility and effectiveness of the proposed model, and the overall classification accuracy is 99.32%. The overall classification accuracy of the models using L1 regularization and L2 regularization was 99.26% and 99.23%. Compared with Experiment 2, the overall accuracy of Experiment 4 was improved by 0.14%, and the precision of class S, class V, and class F was all improved, among which the precision of class F was improved more obviously by 5.62%. Through the above analysis, it is concluded that tree regularization can effectively improve the classification accuracy of the network, which is better than the traditional L1 and L2 regularization. Table7 shows the classification results of BiLSTM models under different regularization methods. Figure 7 shows the confusion matrix of heartbeat classification results based on the BiLSTM-Treg model.Table 7
Classification results of BiLSTM models based on different regularization methods.
BiLSTM +L1BiLSTM +L2BiLSTM + TregSe (%)Sp (%)+p (%)Acc (%)Se (%)Sp (%)+p (%)Acc (%)Se (%)Sp (%)+p (%)Acc (%)N99.7398.0099.5599.4199.7397.8099.5199.3899.7897.9599.5499.44S91.7299.9096.1899.6791.7299.8995.8599.6693.3899.9196.5899.73V98.6399.8197.4299.7398.4999.7897.0299.7098.6399.8397.6999.75F74.7199.9287.8499.7272.4199.9694.0399.7472.4199.9694.0399.74Q100.0099.9899.7799.98100.0099.9899.7799.98100.0099.9899.7799.98Figure 7
Confusion matrix of heartbeat classification results based on the BiLSTM-Treg model.


### 5.5. Analyze the Key Nodes of the Simulated Decision Tree

The tree regularization method used in this paper looks for the decision tree representation of the model in the training process of the network. The generated decision tree simulates the decision process of the BiLSTM network model. We call this decision tree a simulated decision tree (SDT). Since there are many feature points in a single heartbeat, the generated SDT is too large, so we selected the tree generated by the top 10 important feature points of SDT when displaying this decision tree, as shown in Figure8. The top 10 important feature points are 126, 112, 162, 121, 153, 80, 224, 93, 100, and 120. The positions of these feature points corresponding to the ECG waveform are as follows: sampling points 126, 120, 121, and 153 correspond to ST segment, sampling point 112 to J point, sampling point 224 corresponds to the endpoint of T wave, sampling point 162 corresponds to the beginning point of T wave, sampling point 80 corresponds to the peak value of Q wave, sampling point 93 corresponds to the peak value of R wave, and sampling point 100 corresponds to the peak value of S wave, as shown in Figure 9.Figure 8
The simulated decision tree.Figure 9
The key feature points of the decision tree correspond to the positions in the ECG waveform.In Figure8, we have modified the representation of the value field in the decision tree node. We represent the value in the value field as the percentage of the number of heartbeats of N, S, V, F, and Q in the total number of heartbeats of the corresponding category. Taking node 2 as an example, 0.08 in the value field represents that the number of class S heartbeats in this node accounts for 0.08% of the total number of class S heartbeats, which means that this node almost contains no class S heartbeats. Therefore, according to this simulated decision tree, we have the following analysis:(1)
Sampling point 126 is the root node of the simulated decision tree. According to whether the voltage value at this point is less than −0.0692 mV, the sample can be divided into two parts, namely, node 2 and node 3. In node 2, the heartbeat of classes F andQ is relatively large, while the heartbeat of the other three categories is relatively small. Therefore, 28.95% of class F heartbeats and 46.22% of class Q heartbeats were separated from the total sample according to the sampling point 126. Analysis of the reason: sampling point 126 is the point of ST segment in the ECG waveform. ST segment refers to the segment between the end of the QRS complex and the beginning of the T wave, representing the period between ventricular depolarization and ventricular repolarization [39]. The normal ST segment is smooth and flush with the baseline.(2)
It is shown by nodes 11 and 12 that node 2 distinguishes the F heartbeats from theQ heartbeats according to the value of sampling point 224. There is only 0.38% of class Q heartbeat in node 11 and 0% of class S heartbeat in node 12. Analysis of the reason: sampling point 224 is the endpoint of T wave in the ECG waveform. T wave is a wave with a larger amplitude and longer duration after the QRS complex, which shows the process of ventricular repolarization.(3)
It can be shown from node 5 that node 3 separates 25.1% of class V heartbeats and 25.53% of classQ heartbeats from node 3 according to the value of sampling point 112, and it is shown by node 14 and node 15 that node 5 distinguishes the heartbeats of class S from class Q according to the value of sampling point 153. Analysis of the reason: sampling point 112 is the J point in the ECG waveform, and J point is the junction point between the end of the QRS complex and the beginning of the ST segment.(4)
As indicated by node 13, node 4 separates 26.00% of class V heartbeats from node 4 according to the value of sampling point 162. As indicated by node 16, node 6 separates 14.85% of class V heartbeats and 12.59% of class F heartbeats from node 6 according to the value of sampling point 80. Sampling point 162 and sampling point 80 areT wave start points and Q wave peak values, respectively.(5)
It is shown by node 8 that 11.88% of N, 34.33% of S, 13.11% of V, 3.22% of F, and 19.53% ofQ heartbeats are separated from the sample of node 7 according to the value of sampling point 93. After passing through nodes 9 and 10, 6.81% of class V is sorted out at node 18, 15.78% of class Q is sorted out at node 19, and 21.62% of class S heartbeat is sorted out at node 20. The reason is analyzed as follows: sampling point 93 and sampling point 100 are, respectively, R wave and S wave in ECG waveform, which together with Q wave corresponding to sampling point 80 constitute QRS complex. The QRS complex is a group of wave groups with complex changes and large amplitude, showing the process of ventricular depolarization [40].To verify that the BiLSTM-Treg algorithm focuses on and learns from these medically significant feature points, in Experiment 5, we only used these 10 important feature points as the features of a single heartbeat and used the BiLSTM-Treg algorithm to classify the heartbeat. The experimental results are shown in Table8, and the overall classification accuracy is 98.45%. Compared with Experiment 4, Experiment 5 showed no significant decrease in all other metrics except the sensitivity of class S. The experimental results validate the importance of these medically significant feature points in the model.Table 8
Classification results based on key feature points and BiLSTM-Treg algorithm.
Se (%)Sp (%)+p (%)Acc (%)N99.2895.4598.9898.58S77.8199.6185.1499.01V97.9499.7496.3599.62F73.5699.9388.8999.72Q99.8999.9799.6699.96


### 5.6. Comparison with Previous Studies

Table9 compares the classification performance of this method and other literature methods. The experimental data of other pieces of literature also comes from the MIT-BIH arrhythmia database. It can be seen from Table 9 that the method proposed in this paper has the best classification accuracy, with an overall classification accuracy of 99.32%. The classification methods in literature [23, 25] all use the BiLSTM model. The results show that the proposed method has obvious advantages in all metrics except for the low sensitivity of class F, and the classification accuracy is 2.03% and 0.74% higher than the two methods, respectively. From the perspective of heartbeat type, the sensitivity of class S is significantly improved by the method presented in this paper compared with other methods. Compared with the literature [21], the method presented in this paper makes all metrics of Q heartbeat better, especially the sensitivity of Q heartbeat increased by 2.25%. In this paper, a classification method is proposed to integrate the rhythmic information between heartbeats that doctors are concerned about into the time-series network so that the network can learn this information effectively. Moreover, the bidirectional time-series network model can more conveniently obtain the context information of the heartbeat segment, so the algorithm in this paper can have better classification performance in the heartbeat classification problem.Table 9
Comparison with other studies.
ReferenceClassifierPerformance (%)Feature engineeringYang et al., 2021 [9]Random forestAcc = 98.1Se = 75.2+p = 93.9Ji et al., 2021 [15]Stacking-DWKNNAcc = 99.01Sen = 99.65; Spn = 94.94; +Pn = 99.38Ses = 89.42; Sps = 99.85; +Ps = 94.90Sev = 97.21; Spv = 99.78; +Pv = 97.07Sef = 80.77; Spf = 99.94; +Pf = 88.73Zhu et al., 2018 [7]SVMAcc = 97.80Sen = 99.27; +Pn = 98.48Ses = 87.47; +Ps = 95.25Sev = 94.71; +Pv = 95.22Sef = 73.88; +Pf = 86.09Deep learningPandey et al., 2017 [21]9-layer CNNAcc = 94.03Sen = 91.54; Spn = 96.71; +Pn = 87.43Ses = 90.59; Sps = 98.63; +Ps = 94.30Sev = 94.22; Spv = 98.84; +Pv = 95.30Sef = 96.06; Spf = 98.67; +Pf = 94.76Seq = 97.75; Spq = 99.69; +Pq = 98.73Ji et al., 2019 [20]1D-CNNAcc = 99.21Sen = 98.27; Spn = 99.39Sev = 97.54; Spv = 99.44Sef = 98.07; Spf = 99.50Wu et al., 2020 [23]CNN-BiLSTMAcc = 97.29Sen = 98.57; Spn = 93.62; +Pn = 98.81Ses = 84.97; Sps = 99.13; +Ps = 82.80Sev = 94.90; Spv = 99.35; +Pv = 94.00Sef = 76.89; Spf = 99.77; +Pf = 80.45Pandey et al., 2021 [25]BiLSTMAcc = 98.58Sen = 99.54; +Pn = 99.44Ses = 92.00; +Ps = 91.02Sev = 95.81; +Pv = 96.80Sef = 80.55; +Pf = 85.22ProposedBiLSTM-TregAcc =99.32Sen = 99.78; Spn = 97.95; +Pn = 99.54Ses = 93.38; Sps = 99.91; +Ps = 96.58Sev = 98.63; Spv = 99.83; +Pv = 97.69Sef = 72.41; Spf = 99.96; +Pf = 94.03Seq = 100.00; Spq = 99.98; +Pq = 99.77Bold values represent the best experimental results which correspond to the evaluation criteria for one certain type.


## 5.1. Analysis of Experimental Results of Different Time-Series Networks

In order to select the optimal time-series network model, Experiment 1 selected three network models, namely, RNN, GRU, and LSTM, for heartbeat classification. The experimental results show that the overall classification accuracy of the RNN model and GRU model is 98.98% and 98.97%, respectively. The overall classification accuracy of the LSTM model is 99.09%, which is better than that of the RNN model and GRU model. However, it cannot fully consider the rhythm information by using the one-way recurrent neural network for heartbeat classification. Table4 shows the classification results and performance of three one-way recurrent neural networks.Table 4
Comparison of the classification results of RNN, GRU, and LSTM network models.
RNNGRULSTMSe (%)Sp (%)+p (%)Acc (%)Se (%)Sp (%)+p (%)Acc (%)Se (%)Sp (%)+p (%)Acc (%)N99.6197.1099.3599.1599.4597.8099.5199.1599.6997.4099.4299.27S90.4099.8092.8699.5492.7299.7792.1199.5892.0599.9096.1999.68V97.6699.8097.2699.6697.9499.7696.6199.6396.9899.7796.8499.59F71.2699.9491.1899.7271.2699.9186.1199.6875.8699.9186.8499.72Q99.4399.9499.3299.9099.7799.9098.8899.8999.5599.9799.6699.94


## 5.2. Analysis of Experimental Results of Different Bidirectional Time-Series Networks

The one-way recurrent neural network can only learn the heartbeat information before the current moment when performing heartbeat classification. Therefore, we improve the selected LSTM network to BiLSTM so that the network can consider both the previous heartbeat information and the future heartbeat information. And the BiRNN and BiGRU networks are used for comparison and verification. The experimental results show that the overall classification accuracy of the BiRNN model and BiGRU model is 99.13% and 98.92%, respectively. The overall classification accuracy of the BiLSTM model is 99.18%, which is better than that of the BiRNN model and BiGRU model. Table5 shows the classification results and performance of the three bidirectional recurrent neural networks.Table 5
Comparison of the classification results of BiRNN, BiGRU, and BiLSTM network models.
BiRNNBiGRUBiLSTMSe (%)Sp (%)+p (%)Acc (%)Se (%)Sp (%)+p (%)Acc (%)Se (%)Sp (%)+p (%)Acc (%)N99.6597.6599.4799.2999.6297.0599.3499.1599.6498.1599.5999.37S90.4099.8193.1799.5589.0799.8293.4099.5292.7299.8393.9699.63V98.2199.8397.6899.7397.1299.8097.2599.6398.6399.7696.6499.68F74.7199.9389.0499.7367.8299.9084.2999.6470.1199.9388.4199.69Q100.0099.9799.6699.9799.7799.9198.9999.90100.0099.9899.7799.98


## 5.3. Select the Optimal Length of Heartbeat Segment

In order to select the optimal length of the heartbeat segment, a total of 7 experiments were conducted. The length of heartbeat segments selected by us is 1, 5, 10, 15, 20, 25, and 30, respectively, and the corresponding timestep of the BiLSTM is also 1, 5, 10, 15, 20, 25, and 30, respectively. The experimental results show that the classification accuracy of the network is gradually improved when the length of the heartbeat segment is less than 15. However, when the length of the heartbeat is greater than 15, the classification performance of the network decreases rapidly. The main reason is that the rhythm information of heartbeat, such as bigeminy, trigeminy, atrial tachycardia, and ventricular tachycardia, can be shown within 15 beats. When the heartbeat segment is too long, the heartbeat information considered by the network is too redundant, which will affect the network performance. Table6 shows the classification results of the BiLSTM network with different lengths of heartbeat segments.Table 6
Effects of heartbeat segments of different lengths on the classification results of BiLSTM model.
Time step151015202530Overall accuracy (%)99.0499.0299.1299.1898.5582.5284.53


## 5.4. Analyze the Experimental Results of Different Regularization Methods

In order to improve the generalization ability of BiLSTM and further improve the classification accuracy, we choose tree regularization to constrain the weight of the network and use the traditional L1 and L2 regularization for comparison. Experimental results verify the feasibility and effectiveness of the proposed model, and the overall classification accuracy is 99.32%. The overall classification accuracy of the models using L1 regularization and L2 regularization was 99.26% and 99.23%. Compared with Experiment 2, the overall accuracy of Experiment 4 was improved by 0.14%, and the precision of class S, class V, and class F was all improved, among which the precision of class F was improved more obviously by 5.62%. Through the above analysis, it is concluded that tree regularization can effectively improve the classification accuracy of the network, which is better than the traditional L1 and L2 regularization. Table7 shows the classification results of BiLSTM models under different regularization methods. Figure 7 shows the confusion matrix of heartbeat classification results based on the BiLSTM-Treg model.Table 7
Classification results of BiLSTM models based on different regularization methods.
BiLSTM +L1BiLSTM +L2BiLSTM + TregSe (%)Sp (%)+p (%)Acc (%)Se (%)Sp (%)+p (%)Acc (%)Se (%)Sp (%)+p (%)Acc (%)N99.7398.0099.5599.4199.7397.8099.5199.3899.7897.9599.5499.44S91.7299.9096.1899.6791.7299.8995.8599.6693.3899.9196.5899.73V98.6399.8197.4299.7398.4999.7897.0299.7098.6399.8397.6999.75F74.7199.9287.8499.7272.4199.9694.0399.7472.4199.9694.0399.74Q100.0099.9899.7799.98100.0099.9899.7799.98100.0099.9899.7799.98Figure 7
Confusion matrix of heartbeat classification results based on the BiLSTM-Treg model.


## 5.5. Analyze the Key Nodes of the Simulated Decision Tree

The tree regularization method used in this paper looks for the decision tree representation of the model in the training process of the network. The generated decision tree simulates the decision process of the BiLSTM network model. We call this decision tree a simulated decision tree (SDT). Since there are many feature points in a single heartbeat, the generated SDT is too large, so we selected the tree generated by the top 10 important feature points of SDT when displaying this decision tree, as shown in Figure8. The top 10 important feature points are 126, 112, 162, 121, 153, 80, 224, 93, 100, and 120. The positions of these feature points corresponding to the ECG waveform are as follows: sampling points 126, 120, 121, and 153 correspond to ST segment, sampling point 112 to J point, sampling point 224 corresponds to the endpoint of T wave, sampling point 162 corresponds to the beginning point of T wave, sampling point 80 corresponds to the peak value of Q wave, sampling point 93 corresponds to the peak value of R wave, and sampling point 100 corresponds to the peak value of S wave, as shown in Figure 9.Figure 8
The simulated decision tree.Figure 9
The key feature points of the decision tree correspond to the positions in the ECG waveform.In Figure8, we have modified the representation of the value field in the decision tree node. We represent the value in the value field as the percentage of the number of heartbeats of N, S, V, F, and Q in the total number of heartbeats of the corresponding category. Taking node 2 as an example, 0.08 in the value field represents that the number of class S heartbeats in this node accounts for 0.08% of the total number of class S heartbeats, which means that this node almost contains no class S heartbeats. Therefore, according to this simulated decision tree, we have the following analysis:(1)
Sampling point 126 is the root node of the simulated decision tree. According to whether the voltage value at this point is less than −0.0692 mV, the sample can be divided into two parts, namely, node 2 and node 3. In node 2, the heartbeat of classes F andQ is relatively large, while the heartbeat of the other three categories is relatively small. Therefore, 28.95% of class F heartbeats and 46.22% of class Q heartbeats were separated from the total sample according to the sampling point 126. Analysis of the reason: sampling point 126 is the point of ST segment in the ECG waveform. ST segment refers to the segment between the end of the QRS complex and the beginning of the T wave, representing the period between ventricular depolarization and ventricular repolarization [39]. The normal ST segment is smooth and flush with the baseline.(2)
It is shown by nodes 11 and 12 that node 2 distinguishes the F heartbeats from theQ heartbeats according to the value of sampling point 224. There is only 0.38% of class Q heartbeat in node 11 and 0% of class S heartbeat in node 12. Analysis of the reason: sampling point 224 is the endpoint of T wave in the ECG waveform. T wave is a wave with a larger amplitude and longer duration after the QRS complex, which shows the process of ventricular repolarization.(3)
It can be shown from node 5 that node 3 separates 25.1% of class V heartbeats and 25.53% of classQ heartbeats from node 3 according to the value of sampling point 112, and it is shown by node 14 and node 15 that node 5 distinguishes the heartbeats of class S from class Q according to the value of sampling point 153. Analysis of the reason: sampling point 112 is the J point in the ECG waveform, and J point is the junction point between the end of the QRS complex and the beginning of the ST segment.(4)
As indicated by node 13, node 4 separates 26.00% of class V heartbeats from node 4 according to the value of sampling point 162. As indicated by node 16, node 6 separates 14.85% of class V heartbeats and 12.59% of class F heartbeats from node 6 according to the value of sampling point 80. Sampling point 162 and sampling point 80 areT wave start points and Q wave peak values, respectively.(5)
It is shown by node 8 that 11.88% of N, 34.33% of S, 13.11% of V, 3.22% of F, and 19.53% ofQ heartbeats are separated from the sample of node 7 according to the value of sampling point 93. After passing through nodes 9 and 10, 6.81% of class V is sorted out at node 18, 15.78% of class Q is sorted out at node 19, and 21.62% of class S heartbeat is sorted out at node 20. The reason is analyzed as follows: sampling point 93 and sampling point 100 are, respectively, R wave and S wave in ECG waveform, which together with Q wave corresponding to sampling point 80 constitute QRS complex. The QRS complex is a group of wave groups with complex changes and large amplitude, showing the process of ventricular depolarization [40].To verify that the BiLSTM-Treg algorithm focuses on and learns from these medically significant feature points, in Experiment 5, we only used these 10 important feature points as the features of a single heartbeat and used the BiLSTM-Treg algorithm to classify the heartbeat. The experimental results are shown in Table8, and the overall classification accuracy is 98.45%. Compared with Experiment 4, Experiment 5 showed no significant decrease in all other metrics except the sensitivity of class S. The experimental results validate the importance of these medically significant feature points in the model.Table 8
Classification results based on key feature points and BiLSTM-Treg algorithm.
Se (%)Sp (%)+p (%)Acc (%)N99.2895.4598.9898.58S77.8199.6185.1499.01V97.9499.7496.3599.62F73.5699.9388.8999.72Q99.8999.9799.6699.96


## 5.6. Comparison with Previous Studies

Table9 compares the classification performance of this method and other literature methods. The experimental data of other pieces of literature also comes from the MIT-BIH arrhythmia database. It can be seen from Table 9 that the method proposed in this paper has the best classification accuracy, with an overall classification accuracy of 99.32%. The classification methods in literature [23, 25] all use the BiLSTM model. The results show that the proposed method has obvious advantages in all metrics except for the low sensitivity of class F, and the classification accuracy is 2.03% and 0.74% higher than the two methods, respectively. From the perspective of heartbeat type, the sensitivity of class S is significantly improved by the method presented in this paper compared with other methods. Compared with the literature [21], the method presented in this paper makes all metrics of Q heartbeat better, especially the sensitivity of Q heartbeat increased by 2.25%. In this paper, a classification method is proposed to integrate the rhythmic information between heartbeats that doctors are concerned about into the time-series network so that the network can learn this information effectively. Moreover, the bidirectional time-series network model can more conveniently obtain the context information of the heartbeat segment, so the algorithm in this paper can have better classification performance in the heartbeat classification problem.Table 9
Comparison with other studies.
ReferenceClassifierPerformance (%)Feature engineeringYang et al., 2021 [9]Random forestAcc = 98.1Se = 75.2+p = 93.9Ji et al., 2021 [15]Stacking-DWKNNAcc = 99.01Sen = 99.65; Spn = 94.94; +Pn = 99.38Ses = 89.42; Sps = 99.85; +Ps = 94.90Sev = 97.21; Spv = 99.78; +Pv = 97.07Sef = 80.77; Spf = 99.94; +Pf = 88.73Zhu et al., 2018 [7]SVMAcc = 97.80Sen = 99.27; +Pn = 98.48Ses = 87.47; +Ps = 95.25Sev = 94.71; +Pv = 95.22Sef = 73.88; +Pf = 86.09Deep learningPandey et al., 2017 [21]9-layer CNNAcc = 94.03Sen = 91.54; Spn = 96.71; +Pn = 87.43Ses = 90.59; Sps = 98.63; +Ps = 94.30Sev = 94.22; Spv = 98.84; +Pv = 95.30Sef = 96.06; Spf = 98.67; +Pf = 94.76Seq = 97.75; Spq = 99.69; +Pq = 98.73Ji et al., 2019 [20]1D-CNNAcc = 99.21Sen = 98.27; Spn = 99.39Sev = 97.54; Spv = 99.44Sef = 98.07; Spf = 99.50Wu et al., 2020 [23]CNN-BiLSTMAcc = 97.29Sen = 98.57; Spn = 93.62; +Pn = 98.81Ses = 84.97; Sps = 99.13; +Ps = 82.80Sev = 94.90; Spv = 99.35; +Pv = 94.00Sef = 76.89; Spf = 99.77; +Pf = 80.45Pandey et al., 2021 [25]BiLSTMAcc = 98.58Sen = 99.54; +Pn = 99.44Ses = 92.00; +Ps = 91.02Sev = 95.81; +Pv = 96.80Sef = 80.55; +Pf = 85.22ProposedBiLSTM-TregAcc =99.32Sen = 99.78; Spn = 97.95; +Pn = 99.54Ses = 93.38; Sps = 99.91; +Ps = 96.58Sev = 98.63; Spv = 99.83; +Pv = 97.69Sef = 72.41; Spf = 99.96; +Pf = 94.03Seq = 100.00; Spq = 99.98; +Pq = 99.77Bold values represent the best experimental results which correspond to the evaluation criteria for one certain type.


## 6. Conclusion

In this paper, an intelligent classification of heartbeat based on the BiLSTM-Treg algorithm is proposed, which integrates rhythm information between heartbeats. This method fully considers the information of heart rhythm, which doctors pay attention to when diagnosing heart disease, and realizes the automatic classification of heartbeats. In this paper, the influence of different lengths of heartbeat segments on the classification results of the model is analyzed to select the best heartbeat segment length. On this basis, the BiLSTM-Treg algorithm was used for heartbeat classification. Experiments were carried out on the MIT-BIH arrhythmia database, and the results showed that the method can effectively distinguish five types of heartbeats, N, S, V, F, andQ, and the overall classification accuracy rate is 99.32%. The significance of this study is to provide patients with more accurate medical care services. The highlight of this study are as follows:(1)
The heartbeat segment containing rhythm information between heartbeats was selected as the characteristics of the heartbeat sample, and the BiLSTM-Treg algorithm was used to automatically learn the potential rhythm information of individuals(2)
A tree regularization method is proposed to optimize the BiLSTM-Treg algorithm and improve the accuracy of heartbeat classification(3)
By analyzing the key nodes of the simulated decision tree, the interpretability of the BiLSTM-Treg algorithm is analyzed(4)
The experimental results show that the algorithm proposed in this paper can effectively realize the classification of arrhythmiaIn the future study, we will collect more class F-type heartbeat data for pretraining of the model so as to obtain more accurate intelligent ECG diagnosis results.



---

*Source: 8642576-2021-12-13.xml*