A Machine Learning Approach For Classification Of Cardiac Arrhythmia

Mansimransinghanand
3 min readApr 7, 2022

An interesting Use case that I had worked on recently is to understand and detect and classify various types of Cardiac Arrhythmia’s.

There have been rapid advancements being made in the field of technology to assist the medical sector, and improve the medical industry by integrating the latest technology with science. Technology is being used for early detection of diseases and subsequently their efficient and rapid cure. One of the most prevalent medical conditions in India and in the world in general is Cardiac Arrhythmia (also known as irregular heartbeat or heart arrhythmia). It is a medical condition in which the electrical activity of the heart is irregular or is faster or slower than normal. , and is responsible for about more than 10 million deaths per year in India alone. In India, a death is recorded every 33 seconds due to heart attack.

I worked on a solution to classify ECG data into one of the sixteen types of arrhythmia. We here are using the UCI Machine Learning Repository dataset of cardiac arrhythmia to train the system on 279 different attributes.

With new machine learning models and abundance of test data available, there is a huge scope of technology in the medical field. The automatic interpretation of electrocardiography (ECG) data can provide continuous analysis of heart activity, allowing the effective use of wireless devices. An intelligent ECG monitoring system is proposed to detect the possibility of arrhythmia in real time. A wearable ECG sensor continuously measures the activity of a patient’s heart. Various other transforms like DFT, DCT, and other time frequency methods can be used to extract the features that will ultimately help in improving gate accuracy of the classification.

Lets deep dive into the methodology :-

Using MLP Algorithm

  1. Initialize the Neural Network to be Sequential
  2. Create the Input Layer having 175 nodes (as we have 175 features) and set dropout to 0.3.
  3. Add 1st Hidden Layer and set activation function to rectifier or ‘relu’ and dropout to 0.3.
  4. Similarly Add 2nd Hidden Layer and set activation function to rectifier or ‘relu’ and dropout to 0.3 having only 13 significant outputs.
  5. Similarly add 3rd Hidden Layer just as the 2nd Hidden Layer.
  6. Finally add the Output Layer and set activation function as Softmax.
  7. Train the built Neural Network and set epochs to 500

Using Pan Tomkins Algorithm

  1. Read the Raw ECG data.
  2. Apply the Butterworth bandpass filter to remove noise from the data.
  3. Differentiate the Filtered Data.
  4. Square the Differentiated ECG data in Step 3.
  5. Integrate the data output in step 4 to identify the maxima’s which gives us the QRS peaks.
  6. Overlap the peaks identified in the previous step onto the raw ECG data.

Result Analysis

The module in which MLP is implemented and the accuracy is obtained. To test and compare the accuracy we implement other algorithms, Random Forest, KNN and SVM. This way results are obtained for both modules in the project.

  • KNN Accuracy — 66.33%
  • SVM Accuracy — 65.62%
  • MLP Accuracy — 76.37%
  • Random Forest Accuracy — 78.14%

With the experiments conducted using the first module the following plots were plotted. The plots are plotted based by implementing the Pan Tompkins algorithm. Each of the steps involved in the algorithm is shown in a different plot. Finally, the QRS peaks are marked and carefully observed.

QRS Peaks

--

--