## 5 Discussion  
In this work, we used a multi-task learning approach to train both an RNN with LSTM architecture and XGBoost for simultaneously classifying the type and intensity of PA and the type of APS using a common feature map. We used data collected during activities of daily living and exercise sessions, relying only on the physiological signals measured noninvasively by the Empatica E4 wristband. The measured biosignals used for discrimination between different APS and PA include a 3-axis accelerometer, BVP, ST, and GSR (HR is reported by E4 based on BVP). The data obtained from the wristband are processed to impute the missing values and to reduce the noise and the artifacts that compromise the data quality. We employed random convolutional kernel transformation to extract a large number of features from the time series signals. We used two different feature selection techniques to select the most informative features, PLS-DA for the classification tasks and PLS for the regression tasks. In order to address the issue of the imbalanced classes, two different approaches are employed: weighted training and ADASYN. The advantage of the multi-task RNN model is that only a single model is developed and maintained rather than many independent classification and regression models. Moreover, in cases where there is similarity between the tasks, multi-task learning can provide consistency in the predictions. Additionally, mutual features were used for multi-classification regression tasks, therefore enhancing the prediction power of the model, and reducing the computational complexity, which makes it a great candidate for real-time implementation on platforms with low computational power. The multi-task LSTM RNN model designed to simultaneously perform classification of APS types (NS, EAS), classification of PA types (SS, SB, TR), and estimation of EE achieves comparable performance to the independent RNNs, with the multi-task RNN having F1 scores of 98.00% for PA and 98.97% for APS, and an RMSE of 0.728 \(\frac{\text{cal}}{\text{hr.kg}}\) for EE estimation using independent testing data. In contrast, the independent RNNs have F1 scores of 99.64% for PA and 98.83% for APS, and an RMSE of 0.666 \(\frac{\text{cal}}{\text{hr.kg}}\) for EE estimation. Multi-task XGBoost achieved F1 scores of 99.89% and 98.31% for the classification of PA types and APS types, respectively, while the independent XGBoost achieved F1 scores of 99.68% and 96.77%, respectively. The results illustrate that multi-task NN and multi-task XGBoost can effectively assess the signals from wearable sensors and effectively enhance the detection of PA and APS. This can be explained by the potential for improved data efficiency in exploiting the shared representations in the data by training one model to predict the related tasks PA and APS jointly. Training independent models to predict the type of PA  
Figure 12: (**a**) Confusion matrix of PA types classification using the independent XGBoost classification (class imbalance mitigated by ADYSN); (**b**) Confusion matrix of APS types classification using the independent XGBoost (ADYSN). and APS without connecting the shared information between the two tasks may require more training data and longer training time to achieve a high level of accuracy. It is crucial to consider the relative risk of misclassification of the different types of PA and APS to the patients with diabetes. For instance, in the case of misclassification of APS events, whether MS or EAS as an NS event, the AP system will not take the proper action on regulation of blood glucose concentration, and consequently, hyperglycemia may occur. Alternately, misclassification of NS as an MS or EAS is harmful since the AP will incorrectly inject additional insulin in an attempt to mitigate APS, leading to hypoglycemia.