Atrial fibrilation (AFib) is one of the most common cardiac arrhythmias, affecting more than
AFib is detected through an electrocardiogram (ECG) that measures the electrical activities due to depolarization and repolarization of the heart's atria and ventricles. A typical cardiac cycle is shown below
where the signal is composed the P, T and U waves and the QRS complex. Along with an uneven separation of the QRS complexes, AFib is characterized by an absence of P-waves in certain instances of the cardiac cycle (depending on the severity).
AFib, along with other arrhythmias, classification done manually is a very expensive and labor-intensive process. One way in which this process can be streamlined is to leverage machine learning techniques. Deep learning techniques have recently become heavily employed in such classification tasks since it reduces the task of feature extraction. ECG signals being time-series data, are naturally suited to being analysed using Recurrent Neural Networks (RNNs) such as LSTMs and GRUs.
On the otherhand, however, time-series data can also be trained on
The dataset used in this project was released as part of the AF Classification from a Short Single Lead ECG Recording: The PhysioNet/Computing in Cardiology Challenge 2017. The training set consists of record_name
'A#####', sampling rate f_s
(all set to sig_len
as important attributes. The dataset also containts REFERENCE.csv
as an annotation file containing the rhythm classification corresponding to each entry. The annotations are as follows -
- 'N' : normal rhythm
- 'A' : afib rhtyhm
- 'O' : other/unclassified rhythm
- '~' : noise
One big drawback that this dataset poses is the large imbalance in the different classes. This, as we will see, poses significant challenges in obtain high scores in evaluation metrics.
class | no. of records |
---|---|
'A' | 738 |
'N' | 5050 |
'O' | 2456 |
'~' | 284 |
We plot instances of each class below
A list of preprocessing steps precede the CNN training of the dataset. These functions are stored in the data_preprocessing.py
module. The ECG signals contained in the dataset are not of uniform lengths, ranging from a maximum of
The first preprocessing step involves fixing the length of all signals to a uniform HDF5
file along with keys containing record_name
.
Now, the most important preprocessing step is converting these
where neurokit2
library which has a lot of functionality related to processing physiological time-series data processing. This library has a built-in function called ecg_process()
which can perform suitable filtering and QRS segmentation (here the hamilton2002
filter us used). Below is an image of a regular cardiac cycle with the QRS complexes isolated and stacked -
The CWTs are then performed on the cleaned signals. The pywt
library contains the cwt
function perform can perform the transformations. For the kernel
where signal_CWT()
function in the data_preprocessing.py
module performs the transformations on all the signals, saving them as
It can be seen that each class of rhythm has distinguishable features across different frequencies. The weights associated with these frequencies can then be used by a CNN to learn patterns in order to perform classifications. It should be noted that the scalograms are highly dependent on the kind of filter used to clean the ECG signals and the wavelet used in the CWT. We are in the process of identifying the ones which yield higher performancec in evaluation metrics.
AlexNet is a CNN architecture that was designed by Alex Krizhevsky, Ilya Sutskever and Geoffrey Hinton as part of the
All in all, the AlexNet architecture has approximately models.py
.
The CNN was trained on three different batch sizes ScalogramDataset()
can be found in the utils.py
module on which image transformations are performed before dataloaders are created. Since the training dataset has not train/validation split, we create one by randomly selecting train and test indices from REFERENCE.csv
, passing the indices to the dataset class.
During data augmentation, a major transformation is normalization where each pixel in each channel is transformed via
where pixel_stats()
function in utils.py
. This yields
and,
The large value of
The model is trained over
Over
All three optimizers display similar performance, with the validation accuracy plateauing to
Using the confusion matrix, the
and
The precisions, recalls and
AFib | Normal | Other | Noise | |
---|---|---|---|---|
Precision | ||||
Recall | ||||
such that the weighted average
The repository is far from complete and more results will be incorporated over time with the aim of improving the accuracy and hamilton2002
and different algorithms may have different efficacies at segmenting QRS complexes. Further, other neural networks, such as those with residual blocks, have not been studied.