Using Deep Learning Detection Of Arrhythmia

The field of deep learning applications is becoming more widespread. The use of traditional algorithms for arrhythmia detection is cumbersome and the algorithm complexity is relatively high. Using the deep learning model to directly input data into the model will make it difficult to effectively segment the data, which will have a large error in the recognition accuracy. We collected data from six commonly used ECG databases and then used the label shuffling method to amplify the samples, effectively overcoming the effects of sample imbalance. The LSTM model is used for feature point detection to effectively locate the key feature points of the ECG signal, thereby completing the segmentation and processing of the data. Finally, the use of a multiple input model single output for arrhythmia detection has achieved significant results. The average accuracy of the final arrhythmia classification of the model reached 0.711. The accuracy of detecting the fusion of ventricular and normal beat and the aberrated atrial premature beat exceeds 0.9.


INTRODUCTION
Electrocardiogram (ECG) plays a significant role in disease diagnosis. For doctors or experts, analysis of ECG data is the primary means of the detecting arrhythmia. With the rise of artificial intelligence, ECG data has been applied as a time series signal for automatic recognition of arrhythmia, such as machine learning algorithms and deep learning algorithms for arrhythmia detection.
Traditional machine learning algorithms mainly includes support vector machines [ CNN is mainly used to extract features for arrhythmia classification. While RNN is mainly based on the intrinsic relationship between data points.
In order to get a better classification effect. We used a multi-input and single-output model. This model not only inherits the characteristics of RNN to identify the relationship between data points, but also has the function of CNN to extract local and global features. At the same time, the classification accuracy is further improved by afferent feature parameters.

System Framework
Our entire system consists of five steps: First, the "Q", "R", and "S" waves in the ECG data sequence are identified by an RNN model as the basis for data segmentation. Then, by using the random shuffling method to amplify the data, the number of samples is balanced. Then, the "Q", "R", and "S" are identified by an RNN model as the basis for data segmentation. Then the data is segmented and processed. Finally, the data is input into the model training to obtain a model that can be classified. Details of the algorithm are as follows.

Feature Point Recognition
For an ECG data sequence, the type of arrhythmia is marked by the heartbeat. We need to segment the data according to some key feature points. So before performing data segmentation, we need a model for feature point detection, which takes ECG data as input and each point label as an output. The Long-Term and Short-Term Memory Model (LSTM) is a typical recurrent neural network that learns the observed sequences. The LSTM network performs well in feature points from ECG data sequences. We tested a variety of bidirectional LSTM network structures for feature point detection, and detected feature points include "Q", "R", "S". We use a 3-layer bidirectional LSTM network. Each layer contains 50 bidirectional LSTM units. The network structure is shown in Fig. 1. In a heartbeat, since the ratio of ordinary points to feature points is close to 200:1. For a single example in the training set, we optimize the cross entropy objective function.

Data Segmentation
After complete the feature points recognition, we segmented data based on feature points. We split the data from "Q" and "S" into "QRS" segment and "SQ" segment. Then two consecutive "SQ" segments and the middle "QRS" segments are used as a heartbeat data for arrhythmia detection.

Data Amplification
Unbalanced sample size will seriously affect the results of model's training, and we used label shuffling for sample amplification. Firstly, the ECG data list is sorted according to the label order. Then calculate the number of samples for each category and get the number of samples for that category with the most samples. Randomly generate a randomly arranged list for each class based on this maximum number of samples. Then, using the number in the list of each category, the number of samples of the respective category is used to obtain an index value, and the ECG data are extracted from the ECG data of the class to generate a random list of the ECG of the class. Finally, connect the random lists of all categories together, make a Random Shuffling, and get the final list of ECG data. After completing the sample balance, the number of arrhythmia samples is equal.

Converting Data into Two-Dimensional Matrices
After completing the sample balance, the number of arrhythmia samples is equal. After many experiments, we have found that converting one-dimensional ECG signal sequences into two-dimensional matrices can extract more ECG waveform information. The "QRS" segment data and "SQ" segment data of the input model need to be twodimensional data. So we need to amplify the one-dimensional sequence data into twodimensional data. We converted 2 "SQ" segment data and 1 "QRS" segment data into a 160x160 binary array (1 at the waveform and 0 at the blank).

Feature Parameters
In order to improve the accuracy of the model, we manually enter 4 parameters into the model: the length of 2 "SQ" segments, the length of one "QRS" segment and the xcoordinate of the "R" wave apex point in the "QRS" segment. We stitch the four parameters into a vector.

Network Architectures
The network structure is the result of our continuous optimization through a lot of experiments. We used a multi-input and single-output model for Arrhythmia classification. The model structure is shown in Fig. 3.   Fig. 3. The multi-input and single-output model structure for Arrhythmia classification.

CNN Sections
The three CNN sections are mainly used to analyze the shape characteristics of the two "SQ" segments and "QRS" segments of the ECG signal. Referring to the network model of VGG, we used a convolution kernel of size 3×3 and a step size of 1×1 to perform a convolution operation on the 160×160 twodimensional data. After the convolution operation was completed, the flattening process was performed.

Bidirectional LSTM Sections
The bidirectional LSTM portion is used to analyze the relationship between the various points in the ECG signal. We spliced the twodimensional data of two "SQ" and one "QRS" in order, and then expanded to a 3000×1 vector using the method of complementing "0". Then we used the vector as input data for the bidirectional LSTM. Each bidirectional LSTM layer includes 256 LSTM units, and dropout layer is added at each layer to prevent over-fitting.

Feature parameters Sections
Feature parameters portion can further improve the accuracy of the model. For example, some kinds of arrhythmia are characterized by a widening or narrowing of the "QRS" interval. We spliced the length of two "SQ" and the "QRS" and the coordinates of the "R" wave summit into a onedimensional data for training.

Experiments
We collected ECG data from 6 databases, including the popular MIT-BIH, CU ventricular tachyarrhythmia database, CU ventricular tachyarrhythmia database, QT database, ST database, St.-Petersburg Institute of cardiological technics 12-lead arrhythmia database and MIT-BIH arrhythmia database P-Wave annotations. The data of the sample library has been expertly verified, and the calibration of all ECG data is accurate. We randomly divide the data into 10 parts and then use the cross-validation method at a 9:1 ratio to test. The lead ways of the ECG data collected includes V1, V2, V3, V4, V5 and MLII. We extracted the data of the MLII for the experiment. The amount of different types of arrhythmia is as Table 1. As can be seen from the table 1, there is a big gap in the amount of data in different categories of data. We divided the data into 10 pieces, amplified data, and then crossvalidated at a 9:1 ratio. We first introduce several common model evaluation terms. True positives (TP): the number that is correctly divided into positive cases. False positives (FP): the number that is incorrectly divided into positive cases. False negatives (FN): the number that is incorrectly divided into negative cases. True negatives (TN): The number of negative cases that are correctly divided. P=FP+TP and F=FP+FN. The correct rate is our most common evaluation index, accuracy = (TP+TN) / (P+N). This is easy to understand. It is the number of samples that are paired divided by the number of samples. Generally speaking, the correct rate is High, the better the classifier. The accuracy of each class is shown in Table 2.

Conclusions
As a whole, the average accuracy of the final arrhythmia classification of the model reached 0.711. The accuracy of detecting the fusion of ventricular and normal beat and the aberrated atrial premature beat exceeds 0.9. Therefore the accuracy of the model is relatively high and has great practical value. Since the data source comes from six different databases, the difference in data collection methods may affect the accuracy of the classification. At the same time, since the accuracy of the feature point recognition is only 99.5%, the accuracy of the final classification is also caused by the recognition error of the feature points. In the past, CNN performed arrhythmia detection only to analyze the one-dimensional ECG data sequence, so that some information on the morphology could not be extracted. We extend the data to a 2dimensional matrix and use the idea of twodimensional graphics recognition for feature extraction. The accuracy is further improved than before. In feature point detection, we implement the detection of "Q", "R" and "S". However, some arrhythmias have obvious features on "P" and "T", and we can further improve the accuracy by extending the characteristic parameters.