## 4 Two-Stage Method for Determining the Type of Human Breathing
### Algorithm
The measurements were made on the Acer Aspire 5 A515-45G-R92Q computer with the following hardware:  
* AMD Ryzen 7 5700U 8x 1.80 GHz;
* AMD Radeon(tm) RX 640;
* 16 Gb RAM 3200 MHz. The results are presented in Table 8. The best accuracy was achieved by hist gradient boosting classifier. Figure 19: The mean model accuracy depending on the window size (sample size of 100 measurements per point). Figure 20: The standard deviation of model accuracy depending on the window size (sample size of 100 measurements per point). The _log_loss_ metric was used to estimate the probabilistic results of model prediction (_predict_proba_, a probabilistic estimate of each classifier class); i.e., we minimized the logarithmic difference between the predicted probabilities and the actual labels. The model strives to minimize that metric, so the smaller it is, the better the accuracy of the model prediction. The metric was calculated using the formula (3):  
\[log\_loss=-\frac{1}{N}\sum_{i=0}^{N-1}\sum_{k=0}^{K-1}y_{i,k}logp_{i,k}, \tag{3}\]  
where \(N\) is the test sample size, \(K\) is the number of classes, \(Y\) is the test sample, \(y_{i,k}\) is the actual value of the considered class, \(P\) is the matrix of probability estimates of each class, and \(p_{i,k}\) is the probability estimate of the considered class [49]. Figure 21 shows the loss function depending on the training epoch for two hist gradient boosting classification models. There is no model overfitting as the graphs show because both functions tend to zero, albeit slowly. \begin{table}
\begin{tabular}{l c c c c c c c c} \hline \hline \multirow{2}{*}{**Model Kind**} & **Number of** & \multirow{2}{*}{**Accuracy**} & **Precision** & **Recall** & **F1-Measure** & **Training time, s** & **Working Time, s** & **log_Loss** \\  & & & & & & & & **Logistic Loss** \\ \hline Random Forest & \multirow{2}{*}{1} & 0.53 & 0.5 & 0.54 & 0.47 & 0.018 & 0.002 & 8.67 \\ Classifier & & & & & & & & \\ Decision Tree & \multirow{2}{*}{1} & 0.51 & 0.46 & 0.51 & 0.46 & 0.004 & 0.001 & 13.24 \\ Classifier & & & & & & & & \\ Catch 22 Classifier & 1 & 0.63 & 0.65 & 0.63 & 0.64 & 8.926 & 8.665 & 0.94 \\ Rocket Classifier & 1 & 0.46 & 0.45 & 0.46 & 0.46 & 11.507 & 5.437 & 18.68 \\ K-Neighbors & 1 & 0.41 & 0.38 & 0.41 & 0.36 & 0.006 & 0.001 & 10.8 \\ Hist Gradient & \multirow{2}{*}{1} & \multirow{2}{*}{0.42} & \multirow{2}{*}{0.51} & \multirow{2}{*}{0.42} & \multirow{2}{*}{0.37} & \multirow{2}{*}{0.324} & \multirow{2}{*}{0.009} & \multirow{2}{*}{4.22} \\ Boosting Classifier & & & & & & & \\ Random Forest & \multirow{2}{*}{2} & \multirow{2}{*}{0.46} & \multirow{2}{*}{0.46} & \multirow{2}{*}{0.46} & \multirow{2}{*}{0.46} & \multirow{2}{*}{0.047} & \multirow{2}{*}{0.485} & \multirow{2}{*}{6.78} \\ Classifier & & & & & & & \\ Catch 22 Classifier & 2 & 0.52 & 0.52 & 0.52 & 0.52 & 0.004 & 0.11 & 13.21 \\ Catch 22 Classifier & 2 & 0.57 & 0.57 & 0.57 & 0.57 & 19.02 & 34.609 & 0.96 \\ Rocket Classifier & 2 & 0.48 & 0.48 & 0.48 & 0.48 & 35.318 & 64.687 & 17.83 \\ K-Neighbors & 2 & 0.4 & 0.4 & 0.4 & 0.4 & 0.005 & 0.407 & 7.89 \\
**Hist Gradient** & \multirow{2}{*}{2} & \multirow{2}{*}{**0.81**} & \multirow{2}{*}{**0.83**} & \multirow{2}{*}{**0.82**} & \multirow{2}{*}{**0.82**} & \multirow{2}{*}{**0.875**} & \multirow{2}{*}{**0.75**} & \multirow{2}{*}{**1.98**} \\
**Boosting Classifier** & & & & & & & & \\ \hline \hline \end{tabular}
\end{table} 
Table 8: Model quality evaluation results. Figure 21: Graphs of the loss function depending on the number of epochs for the composite model: (**a**) the model, determining abdominal breathing; (**b**) the model discerning thoracic and mixed breathing. The main quality evaluation metrics were accuracy and recall. We chose them as the primary metrics because accuracy allows us to assess how correctly our model predicts all the types of breathing, and recall allows us to monitor the wrong results for mixed breathing, which is of particular interest to us.