## 2 Materials and Methods
### Handling Class Imbalances
This work can benefit people with diabetes relying on insulin administration as a therapy to manage their blood glucose concentrations. People with T1D must make frequent adjustments to their insulin therapy throughout the day based on the various physical and psychological states they experience. Although accommodating structured planned exercise is relatively straightforward, as advance information on the time and intensity of the planned future exercise can be used to manually adjust insulin infusion policies, spontaneous unplanned physical activities that occur throughout the day are challenging for people to accommodate in their insulin dosing decisions. Moreover, episodes of acute psychological stress can occur concurrently or independently of PA, such as during stressful driving conditions or running to catch a bus to work, and may be difficult to explicitly accommodate through insulin therapy adjustments. This problem is further complicated by the fact that PA typically reduces BGC (increasing the risk of hypoglycemia), while APS can cause a temporary increase in BGC (increasing the risk of hyperglycemia). Confounding the occurrences of PA with APS may lead to incorrect insulin therapy decisions that exacerbate the glycemic excursion. Using only a limited number of physiological measurements can therefore lead to incorrect assessments of a person's physical and psychological state, and consequently to inappropriate insulin therapy decisions. Applying machine learning to the physiological variables collected from a wearable device generates accurate detection and classification of PA and APS information. Our future work will integrate PA and APS information with artificial pancreas systems for provision of precision medicine through optimal automated insulin delivery in people with diabetes [2; 3]. ## 5 Conclusions

In this work, we have addressed problems involved in detecting the occurrence of individual and concurrent PA and APS events, as well as in differentiating types of PA and APS from data collected with an Empatica E4 wristband. We employed convolutional-based feature extraction by performing random kernel filters on each biosignal to elicit pattern in the signals during different kinds of PA and APS. We evaluated different feature selection algorithms to select a subset of features for discriminating between different types of PA and APS. We then tested different resampling techniques to mitigate the issue of imbalanced classes. The balanced accuracy scores indicate that the ROCKET feature extraction algorithm and suggested sample stacking algorithm are excellent choices for time series classification of PA and APS. The combination of PLS-LDA for feature selection and ADASYN for data balancing provides the best overall performance among all of the considered detection and classification cases. The use of such techniques can provide reliable information on both daily behavior patterns and unexpected events, thereby assisting in treatment that is effective in mitigating the effects of events that can disturb metabolic homeostasis. Conceptualization, M.R.A., M.R. and A.C.; methodology, M.R.A., M.R. and M.S. ; software, M.R.A. and M.A.-L.; validation, M.R.A. and M.A.-L.; formal analysis, M.R.A., M.R. and A.C.; investigation, M.R.A., M.S., M.A.-L.; resources, M.R.A., M.R. and A.C.; data curation, M.S. and M.R.A. ; writing--original draft preparation, M.R.A., M.R. and A.C.; writing--review and editing, M.R.A., M.R. and A.C.; visualization, M.R.A. and M.A.-L.; supervision, M.R. and A.C.; project administration, A.C.; funding acquisition, A.C. All authors have read and agreed to the published version of the manuscript. Financial support from the NIH under the grants 1 DP3 DK101075 and 1R01 DK130049 and the JDRF under grant 2-SRA-2017-506-M-B (made possible through collaboration between the JDRF and The Leona M. and Harry B. Helmsley Charitable Trust) is gratefully acknowledged.