Heartbeat Classification Based on Multifeature Combination and Stacking-DWKNN Algorithm

Arrhythmia is one of the most common abnormal symptoms that can threaten human life. In order to distinguish arrhythmia more accurately, the classification strategy of the multifeature combination and Stacking-DWKNN algorithm is proposed in this paper. The method consists of four modules. In the preprocessing module, the signal is denoised and segmented. Then, multiple different features are extracted based on single heartbeat morphology, P length, QRS length, T length, PR interval, ST segment, QT interval, RR interval, R amplitude, and T amplitude. Subsequently, the features are combined and normalized, and the effect of different feature combinations on heartbeat classification is analyzed to select the optimal feature combination. Finally, the four types of normal and abnormal heartbeats were identified using the Stacking-DWKNN algorithm. This method is performed on the MIT-BIH arrhythmia database. The result shows a sensitivity of 89.42% and a positive predictive value of 94.90% of S-type beats and a sensitivity of 97.21% and a positive predictive value of 97.07% of V-type beats. The obtained average accuracy is 99.01%. Compared to other models with the same features, this method can improve accuracy and has a higher positive predictive value and sensitivity, which is important for clinical decision-making.


Introduction
Cardiovascular disease is one of the main diseases that endanger human health [1]. Arrhythmia is a common cardiovascular syndrome, and accurate identification of arrhythmia is an essential part of the prevention of cardiovascular diseases. Most arrhythmias are harmless, but some may immediately threaten people's lives. Early detection of arrhythmia can prolong life through proper treatment. e electrocardiogram (ECG) is a popular and mature diagnostic tool. It contains basic physiological information for analyzing cardiac function [2] and is the most basic method for the diagnosis of arrhythmia. Different classes of arrhythmias can be detected by analyzing the changes of ECG waveform, but it usually needs to be diagnosed at the onset of the disease. Some patients' symptoms appear infrequently. Traditional electrocardiogram may not capture the electrocardiogram at the time of onset. It is necessary to use dynamic ECG to record long-term cardiac electrical activities [3].
It may be time-consuming and impractical to rely on manual analysis of ECG signals. Moreover, due to the interference of noise and the diversity of ECG waveforms, arrhythmia is difficult to accurately diagnose and easy to be misdiagnosed. At the same time, relying on manual recognition of electrocardiograms often lacks real-time, which may delay the best time for patient treatment. e application of computer-aided intelligent diagnosis to the classification of arrhythmias can help doctors more accurately diagnose arrhythmias and reduce the workload of doctors. In the literature, numerous algorithms have been proposed to achieve an accurate result for the classification, mainly including deep learning-based approaches and feature extraction-based approaches.
Deep neural networks usually work in an end-to-end way, do not require manual feature extraction, and are widely used for ECG classification [4]. However, although they are good at learning feature representations and have produced very competitive performance in a wide range of applications, they cannot analyze the impact of specific features on classification performance. e traditional feature extraction method has achieved good performance in ECG classification. Researchers usually fed the extracted features to the machine learning model to achieve heartbeat classification. e methods employing deep learning-based approaches have generated a competitive classification performance to the feature extraction-based methods. However, the classification performance of deep learning models can still be achieved by simple machine learning models. is means that there is still room for further performance improvements in this method.
In this paper, a heartbeat classification method based on multifeature combination and Stacking-DWKNN models is proposed to address the shortcomings of deep learning methods and traditional machine learning methods. e distance weight KNN algorithm (DWKNN) is to improve the KNN model by setting the weight of distance. e method proposed further improves the performance of the classification. e main contributions of this paper are as follows: (1) Different feature combinations are constructed. e suitability of every single feature is evaluated, and the results of different feature combinations on classification are analyzed to obtain the optimal feature combination.
(2) Different model fusion methods are used for heartbeat classification to obtain the optimal model fusion method. (3) e Stacking-DWKNN model with the optimal feature combination is employed to distinguish normal beat (N), supraventricular ectopic beat (S), ventricular ectopic beat (V), and fusion normal (F), which is of great significance for clinical diagnosis.
e other parts of this paper are structured as follows. Section 2 introduces related work. e methods of heartbeat classification are introduced in Section 3. Experimental analysis and classification results are described in Section 4. Section 5 summarizes the full text.

Related Work
In the early days, the diagnosis of arrhythmias was based on the experience of the doctor. However, due to the diversity of arrhythmias and the corresponding complexity of the ECG waveform, manual analysis methods are no longer applicable. ECG intelligent analysis has become a research focus in recent years. Researchers have developed a diversity of classification methods for arrhythmias.

Arrhythmia Classification Based on Deep Learning.
Deep learning does not require the manual design of feature extractors. It can automatically learn the features of ECG and extract the key features. It has very good robustness and makes the classification of heartbeat more efficient.
Some researchers [5][6][7][8] employed convolutional neural networks (CNNs), which automatically extract the ECG features and significantly improve the final prediction. Some works [9,10] proposed a deep learning architecture based on a convolutional recurrent neural network (GRNN) to detect arrhythmias. Li et al. [11] designed the architecture of the deep neural network, CraftNet, for accurately recognizing the features, and assembled multiple child classifiers to classify heartbeats. Li et al. [12] used long short-term memory (LSTM) model to distinguish different category heartbeats. Ebrahimzadeh et al. [13] extracted a balanced combination of the Hermit features and interval features. And then, a number of multilayer perceptron (MLP) neural networks were employed to classify heartbeats. e results of these researches were remarkable. Deep learning integrates feature learning into the process of modeling, and the classification of heartbeat is simple and effective. However, the requirement of deep learning for searching the optimal combination of features is challenging.
In [27], researchers have extracted ECG morphology, heartbeat intervals, and RR-intervals and then applied a linear classifier model to the classification tasks using the learned features. Sharma et al. [32] used stop-band energy (SBE) minimized dyadic orthogonal filter bank, and wavelet decomposition of the ECG signals was performed. And then fuzzy entropy, Renyi entropy, and fractal dimension features were extracted for accurate classification. e ensemble classifiers fuse the classification results of multiple different classifiers, to achieve better performance than a single classifier. Mondéjar-Guerra et al. [34] trained specific support vector machine models for each feature, and then the multiple SVMs are combined to classify heartbeats. Shi H. et al. [37] constructed a hierarchical classifier improved by threshold and extreme gradient boosting classifier. is method has better classification performance. Javadi et al. [38] integrated a multiple neural network model based on a stacking algorithm for ECG classification, which reduced the classification error rate. Pandey et al. [39] employed an ensemble of SVMs to classify heartbeats into four classes. Rajesh et al. [40] used intrinsic mode functions to get the final features, and the AdaBoost classifier was employed to classify heartbeats. Shi et al. [41] employed a regional feature extraction method and used an ensemble classifier to distinguish heartbeats.
Although the aforementioned studies have achieved a good classification effect, the extracted medically meaningful features are less, part of the information hidden in the ECG is not easy to be revealed, the classification accuracy also needs to be improved, the classifier does not use a cross-validation method, and the robustness needs to be improved. e relevant literature in the related work is summarized in Table 1.

Methods
A typical heartbeat classification method consists of four main modules. Figure 1 shows the frame of the classification method.
e preprocessing module mainly performs denoising and segmentation. Later, 235 points near R peak, P length, QRS length, T length, PR interval, ST segment, QT interval, RR interval, R amplitude, and T amplitude are extracted from the ECG signal. Furthermore, the features are combined and normalized. Finally, the optimal feature combination is fed to the Stacking-DWKNN algorithm, and then the final classification results are obtained. In this section, each module is introduced in detail.

ECG Signal Preprocessing.
Noise mixed in ECG signal includes baseline drift and muscle artifacts, etc. ey weaken the quality of the ECG signal, make the entire ECG waveform ambiguous, and seriously affect the analysis and diagnosis of ECG signals. In this paper, to classify heartbeat more accurately, the noise of raw ECG signal is removed by wavelet transform. Wavelet transform is a signal time-frequency analysis method [42], which can retain the features of ECG signal. Besides, it avoids important physiological details and has a simple calculation process [43,44]. e wavelet transform and wavelet basis functions are as follows: In formula (1), m represents the scale factor and n represents the transforming parameter. ey are mainly used to stretch the basic wavelet function ψ(t), τ reflects the displacement, and m and τ are continuous variables, so it is also called continue wavelet transform (CWT) [42].
A complete heartbeat is composed of three basic waveforms: the P, QRS, and T. e most important step in segmentation is to obtain the positions of the QRS complex. e existing R peak detection methods have obtained sufficient accuracy [45,46]. Each heartbeat contains a pre-R segment and a post-R segment. e pre-R segment before the R peak contains 90 sample points, and the post-R segment after the R peak contains 144 sample points [47]. R wave is the fiducial point for waveform positioning. In this paper, the "Pan-Tompkins" algorithm is used to locate the R waves, and the detected R wave is compared with the marked R wave in the MIT-BIH arrhythmia database. e result of R wave detection is shown in Figure 2. Table 2 shows some results of R wave detection in the MIT-BIH arrhythmia database.

Heartbeat Feature Extraction.
Feature extraction is a process of extracting representative samples from a large amount of data. ese samples are used as features of the final classification. According to the literature [14,15,20,[22][23][24]29], the wavelength, interval, and morphology of ECG signals have important medical significance and can reveal the hidden information in the heartbeat. Hence, based on the detected fiducial points, the 10 feature parameters are extracted for classification in this paper. Figure 3 is the annotation of each feature in the ECG signal. Table 3 summarizes the features extracted in this paper and detailed as follows: (1) Single heartbeat morphology (Morph): 235 sampling points at R peaks from the prepared R peak annotation file are extracted as morphology features. Among them, the pre-R segment contains 90 sample points, and the pos-R segment contains 144 sample points [47]. Before the first or after last detected QRS complex reaches only 235 sampling points, then the corresponding heartbeat is used. (2) P-QRS-T: A complete ECG waveform contains P, QRS, and T waves. P length (P_len), QRS length (QRS_len), and T length (T_len) are important parameters in electrocardiogram. P-QRS-T in this paper is used to represent P, QRS, and T length.  [37][38][39][40][41] (3) Interval: It represents the time interval between different waveform points on the electrocardiogram. RR interval (RR_inter), QT interval (QT_inter), ST segment (ST_seg), and PR interval (PR_inter) are selected in this paper. ese intervals are important for the diagnosis of arrhythmia. (4) Amplitude: R amplitude (R_amp) and T amplitude (T_amp) are selected in this paper. e R amplitude is the wave with the largest amplitude among all waves. e R amplitude is the amplitude after removing noise in this paper. e T wave amplitude reflects the potential changes in the later period of ventricular repolarization.

Feature Combination.
Feature combination is to combine individual features (multiplication, splicing, or Cartesian product) to get new features. In feature combination, the first-order discrete features are often combined to form high-order combination features, so as to resolve more complex problems [48]. e morphology, interval, and amplitude of ECG signal are of great medical significance, which is very important for diagnosing arrhythmias. Because a single feature cannot fully describe the ECG signal, these three types of features are combined in stitching ways, and the effects of different feature combinations on heartbeat classification are analyzed to select the optimal combination in this paper.

Stacking-DWKNN Model Description.
e idea of the stacking method is to use the basic classifier in the first layer to predict the training samples separately. Each DWKNN model is trained using a ten-cross-training process, which divides the training set into ten subsets. For each subset, the remaining dataset is used to train the model, and then the subsets predicted the result.
is process is repeated ten times. e results are used as the training set of the secondary model and use the class label of the original data as the label of the training set of the metaclassifier. e weighted average of the ten prediction results of the test set is used for the final prediction [49]. Figure 4 presents the frame of the Stacking algorithm. And the Stacking algorithm is detailed in Table 4. e first layer of the stacking algorithm integrates four DWKNN algorithms with different parameters in this paper.  As a highly flexible and general classification algorithm, the KNN model can classify various sample distributions and has good classification ability for small sample data [50]. However, when the samples are unbalanced, it may cause that when a new sample is input, the samples of the large capacity class of the K neighbors of the sample are the majority, so the weight method can be used for improvement.
Distance-weighted k-nearest neighbor (DWKNN) is based on the KNN model. e idea of the DWKNN algorithm is to give weights to k-nearest neighbors according to the distances. e neighbors closer to the test sample have greater weight. A weight w i ′ is assigned to the i-th nearest neighbor x MM i of the test sample x ′ in this paper; the distance-weighted is given by [50]: And then, the class y ′ of the test sample x ′ is labeled according to the majority weighted voting mechanism, and Note. e first column is the record name, the second column is the evaluation indicator "false detection rate," the third column is the evaluation indicator "sensitivity," the fourth column is the evaluation indicator "positive predictive value," and the fifth column is the evaluation indicator "accuracy." According to the AAMIEC38 standard, the difference between the detected QRS complex and the manual mark is within 150 ms, which means that the location detection is successful. Journal of Healthcare Engineering the voting formula is shown in (4) [51], where I is the indicating function, and the calculation formula of I is as follows (5) [50]:

Results
In this section, the experimental procedure is described in detail. Our focus is on feature extraction and classification. According to the medical significance of electrocardiogram, ten features are extracted, and then the effect of different feature combinations and Stacking-DWKNN algorithm on the classification results is analyzed. e MIT-BIH arrhythmia database (MIT-AD) is employed in this paper. e classification result is used as a preliminary diagnosis result of the computer to help the doctor make a further diagnosis.

Experimental Data.
All the experiments in this paper are completed on the MIT-AD. e database consists of 48 twolead records digitized at 360 HZ. Each of the ECG records includes one and a half hours of 2-lead dynamic ECG segments [52]. In this paper, the normal (N), supraventricular (S), ventricular (V), and fusion (F) heartbeats in MIT-AD are distinguished. e four types of heartbeats have a total of 101413 records. is paper randomly selected 90% of the heartbeat data for training and the remaining 10% for testing. e specific distribution of data is shown in Table 5.

Evaluation Indicator.
In this paper, the data is divided into a training set and a test set, and the label output of the model is compared with the real label to get the experimental results. e results of N category heartbeat classification are .., h s (x i ) 8: end for 9: learn a metaclassifier 10: learn H based on D s 11: return H calculated by formulas (6)-(9) [42]. S, V, and F heartbeats are calculated in the same way. Description of a confusion matrix is shown in Table 6, where N, S, V, and F represent the real category of heartbeat and n, s, v, and f represent the predicted type of heartbeat.
TN N � Ss + Sv + Sf + Vs + Vv + Vf + Fs + Fv + Ff, (8) For the comprehensive evaluation of the performance, sensitivity (Se), specificity (Sp), positive predictive value (+p), and accuracy (Acc) are used as indicators in this paper. Higher values of these indicators indicate better classification performance. ese four indicators are calculated by the following formula [42].

Experiment and Result Analysis.
To distinguish arrhythmia more accurately, the classification strategy using the multifeature combination and Stacking-DWKNN algorithm is proposed, which is mainly reflected in the experimental part. is section first compares and analyzes the classification results of KNN models with different feature combinations to select the optimal feature combination (Section 4.3.1); later, in order to achieve better classification results, the parameters K of the KNN model are adjusted (Section 4.3.2). Furthermore, different models are compared to verify that the KNN model is the best, and the classification results of the fusion of different models are compared to show that the framework proposed in this paper is better (Section 4.3.3), which are finally compared with other references (Section 4.3.4). Our focus is mainly on the selection of feature combinations and the influence of the model fusion method proposed in this paper on heartbeat classification.

Analysis of Experimental Results of Different Feature
Combinations. In order to select the optimal feature combination, the effects of the KNN model with different feature combinations on heartbeat classification are analyzed, and the above four indicators are used for evaluation. 15 group experiments are performed in experiment I using the KNN model with interval features. e goal of this experiment is to get the optimal interval feature combination.
e classification results of the KNN model with different interval combinations are shown in Table 7. e best accuracy of 95.41% is obtained by P-QRS-T, PR_inter, QT_inter, ST_seg, and RR_inter. e optimal interval combination is represented by Inter, Inter � {P-QRS-T, QT_inter, RR_inter, PR_inter, ST_seg}.
ree groups of experiments are performed in experiment II using the KNN model with amplitude features. e goal of this experiment is to get the optimal amplitude of heartbeat classification. e classification results are represented in Table 8. Compared with the KNN model with R_amp and T_amp, using only R_amp has the same classification effect. Besides, too many heartbeat features will reduce the efficiency of the classifier, so R_amp is selected as the optimal amplitude feature.
rough the above two experiments, the best combination of interval and amplitude features is obtained. e optimal combination of the three types of features is represented by Morph, Inter, and Amp.
In experiment III, in order to analyze the suitability of every single feature, each feature is fed into the KNN model for training. e resulting confusion matrices for the KNN model with a single feature are presented in Table 9. It is obvious that the single heartbeat morphology feature (Morph) is the best descriptor, and the number of correctly classified heartbeats is the largest.         N  9010  12  11  2  9010  12  11  2  8942  27  54  12  9009  13  11  2  S  42  269  1  0  40  271  1  0  77  224  11  0  37  274  1  0  V  22  2  691  1  23  0  690  3  85  8  619  4  22  2  691  1  F  15  0  7  56  12  1  8  57  28  0  9  41  15  0  7  56   8 Journal of Healthcare Engineering confusion matrix, the better the classification effect of the classifier. It can be seen that the best results are almost based on the KNN model with Morph, Inter, and Amp features. e average classification accuracy is 98.88%. From these results, ECG information can be expressed more comprehensively by using interval, amplitude, and morphology features in heartbeat classification.
From the above experiments, it is obvious that the single heartbeat morphology is the optimal single feature for distinguishing the heartbeat. e optimal feature combination is single heartbeat morphology, Inter, and Amp features.
e average classification accuracy is 98.91%. Figure 5 shows the KNN model with optimal features combination of classification results.

Analysis of Experimental Results with Different
Parameters. To achieve better classification performance, the model parameters are adjusted. In the k-nearestneighbor algorithm, the parameter K represents the k neighbors closest to the classified samples. Generally, the K value is too small, and the classification accuracy of the model is low. e K value is too large, and the model is easy to fit. To determine the appropriate K value, ten experiments are conducted with different parameters. Based on different parameter values, the classification results of the KNN model with the optimal feature combination are presented in Table 13.
It is obvious from Table 13 that when k � 4, the performance of the classifier is the best, with a classification accuracy of 98.91%. And the classification results of different parameters are different, indicating that the parameters have a certain influence on the classification results of the model. Afterward, the K-nearest neighbors are given different weights according to their distance from the classified samples. e accuracy of the DWKNN algorithm with the optimal feature combination is 98.96%.

Analysis of Experimental Result Analysis of Different Classifiers.
e performance of different classifiers is mainly compared in this section. From the above experiments, the optimal combination of features is Morph, Inter, and Amp. In this experiment, accuracy (Acc%) is employed as the evaluation indicator to compare the performance differences of support vector machine (SVM), random forest (RF), logistic regression (LR), linear discriminant classifier (LDA), decision tree (DT), gradient boosting decision tree (GBDT), K-nearest neighbor (KNN), and improved KNN (DWKNN) on different datasets. e classification results of the optimal feature combination based on different classifiers are presented in Table 14.
As shown in Table 14, it is obvious that the classification results of the KNN model are the best. e average classification accuracy is 98.91%. e k-nearest neighbors of the KNN model are given different weights (DWKNN), and the classification results are improved. e ensemble of multiple KNN models (Stacking-DWKNN) has a higher classification performance than a single model. e ensemble classifier fully utilized the correctly classified results of base learners and the difference between them.
is demonstrates the outstanding performance of ensemble classifiers and does improve the results of heartbeat classification. e accuracy of the Stacking-DWKNN model with the optimal feature combination is 99.01%. e classification result by five ensemble structures with the optimal feature combination is shown in Table 15. Table 15 lists the 16 metrics of classification results, including Se, Sp, and +p for each beat and the average accuracy. e Stacking-DWKNN structure has the best comprehensive classification ability: yielding the 8 highest scores on 13 metrics. It achieves the best average sensitivity and specificity of 94.26% and 98.63%. Among them, the N category and V category achieved better results. e Stacking-SVM, Stacking-DT, Stacking-GBDT, and Stacking-RF recognized the N category very well but at the cost of low detection rate of F beat. At the same time, the Stacking-DWKNN recognized the S category, and the F category is improved compared to them.
is is because improving the KNN model through weights improves the impact of data imbalance. Figure 6 shows the Stacking-DWKNN model with different features of classification results.
In order to understand the effect of different model fusion methods, based on the DWKNN (baseline1) model, different model fusion methods are used, and the optimal feature vectors are fed to different models, namely, Voting-DWKNN (baseline2), Bagging-DWKNN (baseline2), and Stacking-DWKNN (proposed) algorithm. Table 16 shows the classification performance of different fusion methods with the optimal feature combination. e statistical measures include Se, Sp, and +p for each beat and the average accuracy. From these results, the Stacking-DWKNN model yields the 9 highest scores on 13 metrics; in particular, the three indicators of S-type heartbeat reached the highest, so this model is preferred for heartbeat classification.         Table 17 shows a comparison of the classification result between the proposed method and other studies, which also perform on MIT-AD. e results show that the Stacking-DWKNN model with multiple combinations of features has better classification accuracy than the other methods discussed in this paper. And the average classification accuracy is 99.01%. e method can accurately distinguish between four categories of heartbeats. As can be seen, a comparison of the classification results from the heartbeat perspective shows that the method outperforms [8,11,26,32,34] on all metrics. Compared with [14], the positive predictive value of S beats is slightly lower, but the proposed method has obvious advantages in other indicators. Regarding the sensitivity, the method proposed in this paper achieved higher values compared to previous methods for the majority classes, N and V. But compared with the literature [33,37], the sensitivity of class S and class F is slightly lower. is is due to the lower number of these two types of heartbeats. It can be concluded from the above that the proposed method has better classification performance. e most important arrhythmias (S and V) have all achieved better results.

Conclusions
Accurate classification of arrhythmias is essential for treating patients.
erefore, an intelligent classification method based on multifeature combination and Stacking-DWKNN algorithm is presented in this paper, which can realize the selection of ECG features and heartbeat classification. e results show that the proposed method has a good recognition rate for four heartbeats. e key points of this study are as follows: (1) Different feature combinations are constructed, and the effect of different combinations of features on heartbeat classification is evaluated to select the optimal feature combination, which provides a good application for ECG feature selection (2) e classification effects of several different classifiers are compared to select the optimal classifier, and then different model fusion methods are used for heartbeat classification based on this classifier to obtain the optimal model fusion method (3) e experimental results show that the Stacking-DWKNN model with optimal feature combination can distinguish four different types of the heartbeat e Stacking-DWKNN model first uses DWKNN models to predict samples separately. e training process of each DWKNN model adopts a cross-training method, the prediction results are used as the input of the secondary model to make the final prediction, and then the final classification is determined by combining the classification results of multiple classifiers to achieve better performance than a single classifier. e cross-validation method effectively alleviates the overfitting problem encountered by a single classification algorithm and has strong robustness. e average classification accuracy is 99.01%.
However, the results of F-type are worse than other types because a few F-types have difficulty in analyzing the features of this type of heartbeat in detail. In the future, we need to include the use of multiple leads and add more complex feature fusion methodologies, and also more attention should be paid to improve the performance of F-type.

Data Availability
(1) All datasets used to support the findings of this study are included within the article. (2) All datasets used to support the findings of this study were supplied by the publicly available MIT-BIH database from the Massachusetts Institute of Technology. e URL to access this data is https:// www.physionet.org/cgi-bin/atm/ATM. (3) e coding used to support the findings of this study has not been made available because the source code in this article is part of a national project and is a trade secret, so the source code is not available.

Conflicts of Interest
e authors declare that they have no conflicts of interest.