## 2 Materials and Methods
### Handling Class Imbalances

Table 5: Balanced accuracy score and the number of misclassified samples (values in parentheses) for joint prediction of PA and APS. three different feature selection methods, namely, a PCA-based approach, a technique utilizing the VIP metric in PLS-DA, and SFS. For each feature selection technique, we evaluate four different approaches to handle imbalances in the sizes of the different classes, which can bias the machine learning algorithms. Because data from sedentary states (resting) and non-stress states are much easier to collect, these classes may be overrepresented in the data. For each feature selection approach, we evaluate four different algorithms for handling imbalanced classes: down-sampling the overrepresented classes by removing samples, up-sampling the overrepresented classes by sampling with replacement, weighting the errors with weights inversely proportional to the respective class size, and ADASYN sampling. Recognizing the temporal dependencies in the data, we leverage the LSTM architecture, a type of RNN that is capable of learning order dependence in a sequence of prediction. This systemic study elucidates the abilities of various algorithms for feature selection and the different techniques for handling imbalanced class sizes. The results reported in Tables 5-8 indicate that the balanced accuracy scores for various combinations of data balancing and feature selection techniques range between 96.82% and 99.99%. The number of misclassified samples has a larger variation based on the techniques used, with PLS-DA having the smallest number of misclassifications. The main advantage of PLS-DA over the PCA-based approach is that PLS-DA is a supervised method that encodes the relationships between the large number of extracted features and the target class affiliations composed of the true class labels. Sequential feature selection approaches may perform better when incorporating floating techniques that allow backtracking for an arbitrary number of times, as this facilitates the discarding of one feature at a time for a certain number of total discarded features for as long the quality criterion continues to improve. The use of sequential floating search methods will be further explored in future works. A limitation of sequential feature selection techniques is the absence of selection using orthogonal subspaces, which permits collinearity in features selection. The imbalances in class sizes were well handled by the ADASYN sampling approach, which has the desired properties of reducing bias caused by class imbalances and adaptively transitioning the decision boundary towards the more challenging classification examples. The participants in our study included healthy subjects and subjects with Type 1 diabetes. Acute psychological stress inducements that are accepted by the Institutional Review Boards were limited both in type and intensity. To obtain a large enough dataset, in this study we use data from both healthy and diabetes groups. The developed algorithm is based on information reporting body movement (3D accelerometer signal), body temperature, skin conductivity, and cardio vascular activity (BVP signal). These variables are signals directly recorded by sensors and do not depend on the glycemic condition of subjects. Hence, they indicate the state of the body, namely, activation of the sympathetic and parasympathetic nervous systems (i.e., the presence of acute psychological stress), physical activity, and other states of the body that are not covered in this manuscript, such as sleep characteristics. Therefore, the acute psychological stress detection model presented here is quite general, as it has been tested with samples from both healthy and diabetes subjects. Of course, the effect of acute psychological stress on blood glucose levels is different for subjects without and with diabetes. Glucose concentration estimation for people with Type 1 diabetes is addressed in [72].