# Real-Time Psychological Stress Detection According to ECG Using Deep Learning
## 3 Results  
To achieve real-time stress level detection, we designed a deep neural network and more conventional methods which rely on hand-crafted features and compared their performance. To conduct conventional methods, we preprocessed the ECG signal and extracted 10 features from the time and frequency domains as shown in Figure 8. Then 9 machine learning methods were used to detect the stress level. The results of these models are evaluated based on different window sizes of 1 min and 10 s, respectively. The result based on 1 min is shown in Table 2 where these nine algorithms finally obtained an average accuracy of 0.647, an average recall of 0.557, and an average specificity of 0.810. When using the window of 10 s, the performance of these models decreased. As shown in Table 3, the average accuracy rate dropped to 0.563, the average recall rate dropped to 0.457 and the average specificity dropped to 0.731. The reason is that extracting features of frequency for a shorter window is less effective. \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Algorithms** & **Accuracy** & **Recall** & **Specificity** \\ \hline XGboost & 0.620 & 0.517 & 0.769 \\ Logistic & 0.667 & 0.564 & 0.792 \\ LinearSVM & 0.676 & 0.604 & 0.784 \\ Randomforest & 0.649 & 0.559 & 0.837 \\ Decision Tree & 0.636 & 0.523 & 0.816 \\ Bayes & 0.666 & 0.681 & 0.829 \\ Gauss SVM & 0.676 & 0.459 & 0.799 \\ KNN & 0.636 & 0.581 & 0.834 \\ Adaboost & 0.600 & 0.527 & 0.830 \\ Average & 0.647 & 0.557 & 0.810 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: The accuracy and recall of conventional method on 1 min ECG. Since the goal of this article is to build a model for real-time application, the performances of the proposed framework and the conventional methods for the 10 s window will be compared and analyzed. Among the conventional models, XGboost obtained the highest accuracy of 0.637, the highest recall of 0.492, and the highest specificity of 0.765. The confusion matrices of XGboost is shown in Figure 14. It could be seen from the confusion matrix that XGboost achieved a recall for moderate stress at 0.916, but produced a poor recognition rate on low stress. It also misclassified most high stress states into moderate stress. It was especially difficult to correctly detect both stress and high stress for the conventional models in this particular experiment. The ROC curve of XGBoost (as Figure 15 shows) also indicated that its ability of recognizing high pressure is lower than that of the medium pressure and the low pressure. To determine the optimal parameters of the proposed network, we conducted various experiments. Initially, we preset the number of n_ inputs to 5, the stride of the pooling layer to 8 and use stitching to deal with the output of BiLSTM. Because the ECG signal is quasi-periodic, we set the length of convolutional filter to 200 which corresponds to the average RR interval (0.8 s) at the sampling rate of 250 Hz. The performance of our initial network was as shown in Figure 16 left, and the accuracy with 4 conv filters was only 0.819. We then tried to increase the number of features by augmenting the number of convolution kernels. In Figure 16, it can be seen that as the number of filters increases, the accuracy rate continues to increase, and when the number of filters reaches 32, the network achieved the maximum accuracy of 0.863. Then, the number of convolutions further increased, the accuracy decreased instead, which implied that when the number of filters exceeded 32, no more valid features could be extracted, and the exceeded filters even caused over fitting, which reduced the accuracy of the model in the test set. The 32 was used as the optimal parameter for the conv filter.