## 5 Results and Validation  
The final model's performance was assessed on both the test and validation datasets, promising results that confirm its capacity to generalize well in detecting apnea events.  
The model demonstrated strong performance on the test set, achieving an balanced accuracy of 79%, precision of 68%, recall of 76%, and F1 score 72%, are summarized in Table 3 and Figure 6. The confusion matrix indicates that while a small number of apnea events (true positives) were missed, the model correctly identified the majority, achieving a solid recall for apnea detection, as shown in Figure 6. For non-apnea events (label 0), performance was slightly lower in percentage terms, though the majority were classified correctly. This outcome highlights the model's effectiveness in identifying apnea events while presenting an opportunity to enhance specificity to reduce false positives. Validation metrics, evaluated at the end of the last training epoch, were consistent with test set results. The model achieved an balanced accuracy of 80%, precision of 70%, recall of 81%, and F1 score 75% on the validation set, as summarized in Table 3 and Figure 7. These metrics are slightly elevated relative to the test set, which is a result that aligns with the use of the validation set during training for hyperparameter tuning. The close alignment between test and validation metrics indicates that the model generalizes effectively across different data splits and retains stable performance under varied conditions.  
To further analyze model behavior, a feature was enabled to overlay SpO2 data for each patient in the test set with true and predicted labels shown in Figures 8-10, providing insight into model detections at a sequence level. For instances showing substantial SpO2 variability, the model tended to predict more apnea events (class 1). It performed accurately when the signal's variability correlated with apnea phases but occasionally overpredicted apnea during non-apnea phases that exhibited significant SpO2 fluctuations. For instance, in one patient's SpO2 sequence, the model accurately identified apnea events amidst high-variability periods but showed a tendency to overpredict apnea during other variable sections.  
\begin{table}
\begin{tabular}{c c} \hline \hline
**Hyperparameter** & **Values** \\ \hline Number of neurons & 52 \\ Learning rate & 0.00012 \\ Number of epochs & 200 \\ Batch size & 7000 \\ Optimizer & AdamW \\ Bidirectional & True \\ Dropout & 0.3 \\ LSTM layers & 1 \\ Dense layers & 3 \\ Normalization type & layernorm \\ Hidden size & 2 \\ Scaler & RobustScaler \\ \hline \hline \end{tabular}
\end{table}
Table 2: Hyperparameters selected for model performance testing.  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline  & **Acc.** & **Precision** & **Recall** & **F1 Score** \\ \hline Test set & 0.79 & 0.68 & 0.76 & 0.72 \\ Val. set & 0.8 & 0.7 & 0.81 & 0.75 \\ \hline \hline \end{tabular}
\end{table}
Table 3: The results for LSTM model.  
Figure 6: Confusion matrix of the final model on test set.  
Figure 7: Confusion matrix of the final model on validation set.  
Figure 8: SpO2 of patient X with confusion matrix labels.  
Figure 9: SpO2 of patient Y with confusion matrix labels.  
This pattern suggests that the model might associate high signal variability with apnea phases, which is a tendency that could lead to overdetections.  
Overall, the final model demonstrates a robust balance between recall and loss, effectively detecting apnea events with generalizable performance across datasets. Addressing the model's sensitivity to SpO2 signal variability may further refine its accuracy and reduce overdetection of apnea events during high-variability periods.