# Sleep Apnea Classification Using the Mean Euler-Poincare Characteristic and AI Techniques
## 4 Methodology
### Classification  
The last step of the methodology involves searching for the best classifier. To predict the type of apnea, we use a matrix \(\mathcal{X}\) with 102 columns; columns 1 to 101 contain the stacked EPC values, and the last column represents the target value, where sleep apnea is denoted as 0 and non-apnea as 1. The matrix described is utilized for training the classifier.  
\[\begin{bmatrix}\mathcal{Z}_{1}^{1}&\mathcal{Z}_{2}^{1}&\cdots&\mathcal{Z}_{n }^{1}&Y_{1}\\ \mathcal{Z}_{1}^{2}&\mathcal{Z}_{2}^{2}&\cdots&\mathcal{Z}_{n}^{2}&Y_{2}\\ \vdots&\vdots&\ddots&\vdots&\vdots\\ \mathcal{Z}_{1}^{m}&\mathcal{Z}_{2}^{m}&\cdots&\mathcal{Z}_{n}^{m}&Y_{m}\\ \end{bmatrix}\]  
where \(Z_{j}^{k}\) denotes the predictors with \(j=[1,101]\), and \(Y_{k}\) denotes the class of each patient.  
Figure 5: P-waves and R-peaks from the binary image (excursion set) at level \(\lambda\) = 0.2 for a non-apnea patient. Normally, the P-wave follows a straight line at each level \(u\).  
In our study, we utilized _Classification Learner_, a Matlab toolbox, to model several classifiers. We chose several models to provide a baseline comparison, varying complexity and interoperability. Our objective was to evaluate simple and sophisticated models to observe the complexity of the OSA classification. The results are shown in Table 1,  
Figure 6: EPC values from the sleep apnea patients. Patients from 1 to 20 show OSA events at different times with severe cases. In the majority of these cases, the duration of the OSA event is about 1 hour.  
Figure 7: EPC values from sleep apnea patients with borderline cases (patients 21–25), where activity was less than an hour, and non-apnea patients (patients 26–35), who served as control cases.  
applying EPC models derived from 15 th-order polynomials as inputs for the classifiers. The computations were conducted on an AMD Ryzen 5 processor with 16 GB of RAM, utilizing the parallel pool option. We used \(k\)-fold cross-validation with \(k=5\) in all cases.  
With the results shown previously, we applied an ensemble of K-nearest neighbors (EKNN); this approach can help to improve the prediction with non-informative features [49]. In Figures 6 and 7, we observed all the EPCs from all the patients; analyzing these data presents a challenge, so we employed classifiers to reveal information that aids in their classification.  
Figure 8 presents a diagram of the ensemble KNN classifier, where the EPC models from both healthy and unhealthy patients serve as the training data.  
We conducted a study where we selected 30 learners, each representing a different subspace. For each learner, we randomly chose 65 variables to predict their behavior, resulting in 35 observations for both the training and test phases. In the next section, we will discuss the results and findings of this model in detail. Table 2 shows the parameters used to train the EKNN model using 101 features as inputs. Remember that from the Apnea-ECG database, there are two sets, one called training data and the other called test data, each with 35 records unbalanced in the classes.  
\begin{table}
\begin{tabular}{l l l l l l} \hline \hline
**Type of Classifier** & **Accuracy** & **Sensitivity** & **Specificity** & **F1 Score** & **MCC** \\ \hline Linear SVM & 62.86\% & 70\% & 20\% & 76.36\% & \(-7.75\%\) \\ Decision Tree & 65.71\% & 78.26\% & 41.67\% & 75\% & 20.94\% \\ KNN & 74.29\% & 78.57\% & 57.14\% & 83.02\% & 31.62\% \\ Logistic Regression & 77.14\% & 86.96\% & 58.33\% & 83.33\% & 47.59\% \\ Ensemble KNN & 80\% & 82.14\% & 71.43\% & 86.79\% & 47.43\% \\ \hline \hline \end{tabular}
\end{table}
Table 1: Comparing machine learning techniques to classify sleep apnea using EPC models as inputs.  
Figure 8: The ensemble KNN classifier example; each dataset is composed of 65 random features. In this setup, 30 KNN classifiers (learners) are activated, and the final prediction is determined by a majority vote.