## 2 Materials and Methods
### Classification and Machine Learning  
Once all data had been imported into MATLAB for classification, all three R-R-related SCA features (mean R-R interval duration, RMSSD and SDSD) were then compiled into a singular 1200 \(\times\) 3 matrix based on the time window (e.g., \"3 h prior to SCA\"). The data was then subjected to statistical classification via various classifiers using the Classification Learner App in MATLAB, in order to discriminate between the features extracted from a normal patient to that of a patient at risk of SCA. Each classifier generates a pattern recognition model based on a given set in order to classify future input datasets for SCA risk detection [20]. The data was first subjected to linear discriminant analysis via a linear classifier, which aims to separate input vectors into classes through the use of linear decision boundaries. The within-class scatter matrix (\(S_{w}\)) is modelled as:  
\[S_{w}=\ \sum_{i=1}^{C}\sum_{x\in C_{i}}\left(x-\ m_{i}\right)\left(x-\ m_{i} \right)^{t} \tag{4}\]  
where \(C\) denotes the number of classes, \(C_{i}\) is the set of data belonging to a class and \(m_{i}\) denotes the mean of the class. The between-class scatter matrix (\(S_{B}\)) is modelled as:  
\[S_{B}=\ \sum_{i=1}^{C}(m_{i}-m)\left(m_{i}-m\right)^{t} \tag{5}\]  
where \(m\) denotes the mean of all classes. The criterion function is defined as:  
\[J(W)=\ \frac{\left|W^{t}S_{B}W\right|}{W^{t}S_{w}W} \tag{6}\]  
The overall result is a transformation matrix that maximizes the ratio of between class variance to within class variance so that adequate class separability is obtained [20]. Linear classification was then followed by binary support vector machine (SVM) classification with both a linear SVM and a non-linear fine Gaussian SVM. A support vector machine creates a decision surface by constructing an optimal hyperplane which separates two classes which, in this case, are normal patients and patients at risk of SCA. The optimum hyperplane is found by maximizing the distance between two hyperplanes: \(\mathbf{w}\cdot\mathbf{x}+b=+1\) and \(\mathbf{w}\cdot\mathbf{x}+b=-1\) which is \(2/\left\|\mathbf{w}\right\|\). A slack variable \(\xi_{i}\) is then introduced and the optimal hyperplane is then determined by minimizing:  
\[C\sum_{i=1}^{k}\xi i+\ \frac{1}{2}\left\|\mathbf{w}\right\|^{2} \tag{7}\]  
where \(C\) denotes a cost-constant involving margin size and error. The Langrange multiplier \(\alpha_{i}\) is then used to find the optimal hyperplane by maximizing:  
\[L\left(\alpha\right)=\ \sum_{i=1}^{n}\alpha_{i}-\ \frac{1}{2}\ \sum_{i=1}^{n}\sum_{j=1}^{n} \alpha_{i}\alpha_{j}z_{i}z_{j}\left(\mathbf{x}_{i}\cdot\mathbf{x}_{j}\right) \tag{8}\]  
As the data in this study is non-linear, it can be linearly classified using the RBF function [21]:  
\[k\left(x_{i}\,\ x_{j}\right)=\exp\ (-\gamma\left\|x_{i}-x_{j}\right\|^{2}) \tag{9}\]Performance measurement was then conducted using the performance indicators, accuracy, sensitivity and specificity which were calculated via the confusion matrix generated by MATLAB [19]:  
The accuracy for each time-frame and each classification method were obtained and recorded in order to determine the earliest time-frame in which SCA can be accurately detected. All classifiers were subjected to five-fold cross-validation. The most accurate time-frame and the earliest time-frame exhibiting reasonable accuracy (relative to the values obtained in the preceding time intervals) across all classifiers were then isolated and subjected to further testing to evaluate the sensitivity and specificity across the three different classification methods.