# Cardiac Arrhythmia Classification Based on One-Dimensional Morphological Features
## 2 Materials and Methods
### Machine Learning  
For each ECG lead, we extracted 11 first-order features, 9 GLCM features, and 13 GLRLM features. A total of 33 features were extracted from a single ECG lead. Since we dealt with 12-lead ECG signals, the total number of extracted features was 396 features for each subject. Before applying the morphological features of the 1D signal to the machine learning algorithms, we randomly split the feature sets into a training subset (n = 6776, 64%), a validation subset (n = 1694, 16%), and a test subset (n = 2118, 20%) for 5-fold cross-validation.  
In this study, we investigated six machine learning classifiers (decision tree (DT), k-nearest neighbor (kNN), naive Bayes (NB), random forest (RF), logistic regression (LR), and XGBoost (XGB)). All classifiers were implemented using Scikit-learn ([[https://scikit-learn.org](https://scikit-learn.org)]([https://scikit-learn.org](https://scikit-learn.org)), accessed on 11 October 2021), which provides a user-friendly interface for accessing many machine learning algorithms in Python. During the training phase, machine learning algorithms use training subsets to train the models' weights and employ validation subsets to optimize models' hyperparameters. The optimal hyperparameters were selected based on the accuracy and obtained through a comprehensive grid search. Information on the hyperparameters that were tuned by a grid search is provided in Table 4.  
\begin{table}
\begin{tabular}{c c c} \hline
**GLRLM Feature Names** & **Definition** & **Measure** \\ \hline Short Run Emphasis & \(\frac{1}{N_{max}}\sum_{i}^{p}\sum_{j}^{j}\frac{1}{j^{2}}*Q(i,j)\) & distribution of short run lengths \\ Long Run Emphasis & \(\frac{1}{N_{max}}\sum_{i}^{p}\sum_{j}^{j}\mathcal{Z}*Q(i,j)\) & distribution of long run lengths \\ Gray-Level Nonuniformity & \(\frac{1}{N_{max}}\sum_{j}^{p}\left(\sum_{j}^{j}Q(i,j)\right)^{2}\) & similarity of quantized values in the signal \\ Run-Length Nonuniformity & \(\frac{1}{N_{max}}\sum_{j}^{j}\left(\sum_{j}^{p}Q(i,j)\right)^{2}\) & similarity of run lengths throughout \\ Run Percentage & \(\frac{1}{N_{max}}\) & the signal \\ Low Gray-Level Run Emphasis & \(\frac{1}{N_{max}}\sum_{i}^{p}\sum_{j}^{j}\frac{1}{j^{2}}*Q(i,j)\) & coarseness of the signal \\ High Gray-Level Run Emphasis & \(\frac{1}{N_{max}}\sum_{i}^{p}\sum_{j}^{j}\frac{1}{j^{2}}*Q(i,j)\) & distribution of the lower quantized values \\ Short Run Low Gray-Level Emphasis & \(\frac{1}{N_{max}}\sum_{i}^{p}\sum_{j}^{j}\frac{1}{j^{2}}*Q(i,j)\) & distribution of the higher quantized values \\ Short Run High Gray-Level Emphasis & \(\frac{1}{N_{max}}\sum_{i}^{p}\sum_{j}^{j}\frac{1}{j^{2}}*Q(i,j)\) & joint distribution of shorter run lengths with \\ Long Run Low Gray-Level Emphasis & \(\frac{1}{N_{max}}\sum_{i}^{p}\sum_{j}^{j}\frac{1}{j^{2}}*Q(i,j)\) & higher quantized values \\ Long Run High Gray-Level Emphasis & \(\frac{1}{N_{max}}\sum_{i}^{p}\sum_{j}^{j}\frac{1}{j^{2}}*Q(i,j)\) & joint distribution of long run lengths with \\ Long Run High Gray-Level Emphasis & \(\frac{1}{N_{max}}\sum_{i}^{p}\sum_{j}^{j}\frac{1}{j^{2}}*Q(i,j)\) & lower quantized values \\ Gray-Level Variance & \(\sum_{i}^{p}\sum_{j}^{j}(i-\mu_{i})^{2}*\frac{Q(i,j)}{N_{max}}\) & variance in gray level intensity for the runs \\ Run-Length Variance & \(\sum_{i}^{p}\sum_{j}^{j}\left(j-\mu_{j}\right)^{2}*\frac{Q(i,j)}{N_{max}}\) & variance in runs for the run lengths \\ \hline \end{tabular}
\end{table}
Table 3: GLRLM features. \(Q(i,j)\) is the GLRLM representing the number of runs of quantized gray level \(i\) and consecutive length \(j\). \(N_{run}\) is the number of runs of the GLRLM and \(N_{p}\) is the total signal length. \(\mu_{i}=\sum_{i}^{p}\sum_{j}^{j}i*\frac{Q(i,j)}{N_{max}}\) and \(\mu_{j}=\sum_{i}^{p}\sum_{j}^{j}j*\frac{Q(i,j)}{N_{max}}\).  
The performance of the machine learning models was tested on the unseen test subsets to verify the validity of the proposed feature extraction algorithm.