Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

MPHY0047 – Surgical Data Science

Coursework 4

The Electrocardiogram (ECG) signal is a recording of the cardiac electrical activity which provides important information about the heart's condition. Detection of ECG arrhythmias is necessary for the treatment of patients and for diagnosing the abnormal rhythm at an early stage. However, it is time-consuming for cardiologists to analyze long ECG records in a short period of time and in addition the human eye is poorly suited to detect the morphological variation of the ECG signal. Therefore, there is a need for an effective computer aided diagnostic (CAD) system for heart arrhythmias. Automatic ECG signal analysis faces challenges due to large variations in morphological and temporal characteristics of ECG waveforms in different patients. ECG waveforms may also differ for the same patient at different times. It is not uncommon for ECG classification methods to perform well on the training data but yielding poor performance on the ECG waveforms of  different patients [1].

Problem: ECG arrhythmia classification and CVD analysis

Since 1975, Boston's Beth Israel Hospital (now the Beth Israel Deaconess Medical Center)   and MIT have supported research into cardiac arrhythmia analysis and related subjects. One of the first major products of that effort was the MIT-BIH Arrhythmia Database, which was     completed and began distributing in 1980. The database was the first generally available set of standard test material for evaluation of arrhythmia detectors and has been used for that    purpose as well as for basic research into cardiac dynamics at more than 500 sites worldwide.

Data Description

The MIT-BIH Arrhythmia Database contains 48 half-hour excerpts of two-channel ambulatory ECG recordings, obtained from 47 subjects studied by the BIH Arrhythmia Laboratory between 1975 and 1979. Twenty-three recordings were chosen at random from a set of 4000 24-hour ambulatory ECG recordings collected from a mixed population of inpatients (about 60%) and outpatients (about 40%) at Boston's Beth Israel Hospital; the remaining 25 recordings were selected from the same set to include less common but clinically significant arrhythmias that would not be well-represented in a small random sample.

The recordings were digitized at 360 samples per second per channel with 11-bit resolution over a 10 mV range. Two or more cardiologists independently annotated each record; disagreements were resolved to obtain the computer-readable reference annotations for each beat (approximately 110,000 annotations in all) included with the database.

Since the creation of the database numerous research efforts have focused on the prediction and classification of arrhythmic ECG signals. In this coursework you will apply unsupervised learning methods to investigate the number of different morphological groups (clusters) of ECG heartbeats that are present in the database.

You are going to work with a subset of the MIT-BIH database with a total of 1800 ECG heartbeats that are characterised according to their morphology and grouped in the following three classes (N,S,V) [1]. Samples of ECG heartbeats from each class are shown in Fig.1.

AAMI class

MIT-BIH heart beat types

Normal beat (N)

Normal

beat (N)

Left

bundle

branch

block beat

(L)

Right

bundle

branch

block beat

(R)

Atrial escape

beat (e)

Nodal

(junctional)

escape

beat (j)

Supraventricular ectopic beat (S)

Atrial

premature

beat (A)

Aberrated

atrial

premature

beat (a)

Nodal

(junctional)

premature

beat (J)

Supraventricular

premature beat

(S)

Ventricular ectopic beat (V)

Premature

ventricular

contraction

(V)

Ventricular

escape

beat (E)


The 1800 heartbeats from the 3 groups have been pre-processed and decomposed with the Wavelet db4 transform at 6 levels and from both the approximate and detailed Wavelet        coefficients 83 statistical features (mean, std, median, skewness, kurtosis, rms value, ratio)  were extracted to represent every heartbeat in our dataset. These are all stored in the          ecg_signals_preprocessed.csv file as a 1800x84 array where each row represents the ECG record and each column the extracted Wavelet features. The last column “classes” indicates the class of the record as: 0 – ‘N’, 1 – ‘S’, 2 – ‘V’ .

References

[1] Das MK, Ari S. ECG Beats Classification Using Mixture of Features. Int Sch Res Notices. 2014;2014:178436. Published 2014 Sep 17: doi:10.1155/2014/178436

[2] Moody GB, Mark RG. “The impact of the MIT-BIH Arrhythmia Database”, IEEE Eng in Med and Biol, 20(3):45- 50 May-June 2001: (PMID: 11446209)

[3] Dua, D. and Graff, C. (2019). UCI Machine Learning Repository [http://archive.ics.uci.edu/ml]. Irvine, CA: University of California, School of Information and Computer Science.

Question 1 [20 marks]

Use the kmeans algorithm to cluster the records into the three groups using all 83 features available and report the algorithm’s accuracy, precision, recall and F1-score and the confusion matrix. If required, you can scale the features. Use PCA to reduce the dimensionality of your feature vector but ensure that you maintain above 90% cumulative  explained variance and repeat the kmeans clustering and compare the outcomes. Has dimensionality reduction been beneficial in kmeans clustering?

[Important hint also valid for Q2, Q3]

Please keep in mind that as an unsupervised method kmeans and the rest of the clustering algorithms, has no access to the labels. Depending on the random initialisation seed the     algorithm will try to create 3 clusters without being guided by the class labels (0,1,2) in your records. So, if you have 10 records with the following labels [0,0,0,1,1,1,2,2,2,2]  and you   obtain a clustering result as [1,1,1,2,2,2,0,0,0,0] then this is 100% correct as the algorithm  clustered the 10 records into 3 clusters correctly. You may need to change the label assignments (0,1,2) to be able to generate the confusion matrix and classification metrics.

As a suggestion use random_state = 4

Question 2 [20 marks]

Use Gaussian Mixture Models with Expectation Maximisation to cluster the records into the three groups using all 83 features available and report the algorithm’s accuracy, precision,  recall and F1-score and the confusion matrix. If required, you can scale the features. Use    PCA to reduce the dimensionality of your feature vector but ensure that you maintain above

90% cumulative explained variance, repeat the GMM-EM clustering, and compare the outcomes. Has dimensionality reduction been beneficial in GMM-EM clustering?

As a suggestion use random_state = 9

Question 3 [20 marks]

Use Agglomerative clustering to cluster the records into the three groups using all 83 features available and report the algorithm’s accuracy, precision, recall and F1-score and the confusion matrix. If required, you can scale the features. Try different linkage metrics and      decide on the one that give you the best accuracy. Use PCA to reduce the dimensionality of your feature vector but ensure that you maintain above 90% cumulative explained variance,  repeat the kmeans clustering and compare the outcomes. Has dimensionality reduction been beneficial in Agglomerative clustering?

Compare the three clustering methods and also comment on which of the 3 types of ECG beats is easier to be grouped into a cluster and which is the most difficult.

Question 4 [20 marks]

The first 3000 samples (~10 sec) of the first record are stored in the single_ecg_signal.csv    file. We will use this as test signal to evaluate timeseries modelling and forecasting. Load the signal and investigate its stationarity with the Dickey-Fuller test. Also evaluate the stationarity after performing the following transformations to the signal: i) first difference transformation, ii) square root transformation, iii) log transformation. Decide which version of the signal presents the highest stationarity and use this in the following steps. Use the first    2000 samples as a train set and the remaining as testing set and after performing the seasonal decomposition of the signal, develop: i) an AR model to forecast  the timeseries, ii) a MA model to forecast the timeseries, iii) an ARMA model to forecast the timeseries and iv) an ARIMA model to forecast the timeseries. Use the ACF and PACF to decide on the order of your models and compare them using the RSS.

Question 5 [20 marks]

The statlog heart dataset (https://archive.ics.uci.edu/ml/datasets/statlog+(heart)) is a set of   physiological and lab test parameters for 271 patients examined for cardiovascular (CVD)    conditions [3]. The dataset is provided in the heart-statlog.csv file and the last column ‘class’

designates if a patient has – “present” or does not have – “absent” CVD. Pay attention to the fact that certain variables are categorical (with 2 or 3 values) and some are continuous with  various ranges. Binarize your dataset so that every feature has categorical variables (0,1)    according to the following list.

-- 1. age “0” if value 50 or “1” if value > 50

-- 2. sex – binary already

-- 3. chest pain type (4 values) “0” if value 2.5 or “1” if value > 2.5

-- 4. resting blood pressure – “0” if value ≤ 125 or “1” if value > 125

-- 5. serum cholesterol in mg/dl – “0” if value ≤ 250 or “1” if value > 250

-- 6. fasting blood sugar > 120 mg/dl – binary already

-- 7. resting electrocardiographic results – “0” or “1” (if value≠0)

-- 8. maximum heart rate achieved “0” if value 140 or “1” if value > 140

-- 9. exercise induced angina – binary already

-- 10. oldpeak = ST depression induced by exercise relative to rest – “0” if value = 0 or “1” if value ≠ 0

-- 11. the slope of the peak exercise ST segment – “0” if value = 1 or “1” if value ≠ 1 (be careful)

-- 12. number of major vessels (0-3) colored by flourosopy – “0” if value = 0 or “1” if value ≠ 0 -- 13. thal: 3 = normal; 6 = fixed defect; 7 = reversable defect – “0” if value = 3 or “1” if value  ≠ 3

After you have binarized the dataset perform association analysis using the apriori method to extract and list the most informative rules, using:

A threshold support of 0. 25 to find the frequent itemset

The lift metric with a threshold of 1.15 to extract the association rules

The most significant association rules using conviction (threshold for conviction >1.5)

Finally, attempt to interpret the association rules you extracted considering also the disease class. Are the rules you described indicative of disease presence or absence ?