ECG classification
Training and evaluation of machine learning models for ECG classification using nested cross-validation.
Overview
Context
ECG signals are used to assess the health of the heart. However, especially for long term monitoring it is very time consuming to analyze all the signals. With an average heart rate of 80, a single day creates an amount of almost 7 million heart beats which is unfeasible to manually analyze in practice. Therefore, machine learning can help to find abnormal heart beats which might indicate diseases of the heart or cardio vascular system.
Evaluation Criteria
- Balanced Accuracy is used because the classes are unequally distributed. For example, the class of the normal heart beats is a lot larger than the other classes. However, correctly classifying an abnormal heart beat might be more important.
- F1 weighted is a robust metric for imbalanced datasets and balances precision and recall across all classes.
The Data
The dataset is the MIT-BIH Arrhythmia Database which is downloaded as zip file from the official website12. After unpacking, the data is processed into a pandas Dataframe.
The dataset consists of 48 ~30 min long two - channel ambulatory ECG recordings which was collected from 47 subjects. A two-channel ambulatroy ECG is a portable device used to monitor and record a patients heart activity over an extended period. The recordings have a resolution of 360 samples per second. Each record as annotated by at least two independent cardiologists. The goal is to predict these annotation and to classify the individual heart beat. Therefore, the values at different time points are the data while the annotation is the target to be predicted.
This dataset is suitable for the task described above for several reasons:
- The data is from a two-channel ambulatroy ECG which is typically used for long term monitoring.
- Each heart beat is annotated.
- The dataset quite big with more than 100,000 heart beats.
This means, a model resulting from this project could ideally classify a heart beat from a two-channel ambulatroy ECG.
Note: Detecting the beat itself is not part of this project. In practice, it would be a necessary step to first identify the peaks of heart beats in the ECG signal.
The Project
Note: Below is only part of the implementation. The whole code with all classes and functions can be found in this repository.