# Artificial Intelligence Algorithms for Treatment of Diabetes
## 2 Methods
### ML with Free-Living Data for Digital Health Technologies in T1D
The details of the demographic information of the selected subjects in our work and the definition of the variables collected are provided in [18]. Separate models are developed for each person in order to capture personalized patterns of meal consumption and physical activity. Data lengths vary between a minimum of 30 days up to 700 days of recorded information. The demographic information of the donors is provided in [18]. The donors have used CGM data for adjusting their insulin dosing (by using sensor-augmented-pump or automated insulin delivery) therapy for up to two years. All information except meals and physical activity are recorded every five minutes. As expected, in free-living there are many missing values in data and signal noise that must be addressed by preprocessing the data. The probabilities of a meal or physical activity events or their concurrent presence during one day (24-h period) were obtained by analyzing 15 months of CGM, insulin pump, meal, and physical activity data collected from a randomly selected person with T1D from the Tidepool dataset (Figure 4) illustrate the high probabilities of occurrence of these events spread over time windows ranging from 1 to 3 h, and the peak times for meals and exercise. It will be the task of a ML algorithms to detect and discriminate the daily patterns of behavior for each person. In data preprocessing, data reconciliation, outlier removal, and imputation of missing values are conducted using effective algorithms. The algorithms developed to implement these tasks are reported in [18]. The diagram of workflow for data processing, feature extraction, and modeling is summarized in Figure 5.  
Figure 4: The probability of meal and physical activity events during a day was obtained by analyzing 15 months of the pump-CGM sensor, meal, and physical activity data of a random person with T1D from the Tidepool dataset [18]. For the detection and classification of events, the CGM values and insulin pump data are preprocessed and stacked with the past recorded data. All samples are segmented into three different time windows: the current samples are used for model-based feature extraction, two-hour window of the past data are used for statistical and nonlinear feature variables, and past day samples of the data are used for the frequency domain features. Redundant feature variables are identified and eliminated by a two-step feature selection procedure. First, the deviance statistic test is performed to filter out features with low significance. Then, the training split of all datasets is used in the wrapper feature selection strategy to maximize the accuracy of the classifier in estimating meal and exercise events. Voting and k-fold cross validation are used to assign the current state to one of the four classes: \"Meal and Exercise\" (M and E), \"no Meal but Exercise\" (E), \"no Exercise but Meal\" (M), \"neither Meal nor Exercise\" (No M and E). Event detection is achieved with recurrent neural networks (RNN). RNN models are developed for each individual to capture their behavior more accurately. The RNN models are used in this work to handle the temporal sequential nature of the time-series data, where memory in the network ensures that the current state can effectively influence the future state after a certain allotted time interval. Several RNN model configurations are studied to assess their accuracy and performance in estimating the probabilities of occurrence of these four classes at each sampling time [18]. The feature variables are time-series data, and recorded samples of past values of all feature variables are stacked together to build the tensor of model inputs. These models use a past window of two hours, corresponding to 24 past samples of the recorded CGM and insulin pump data, and extracted features. Event (M, E) estimations are performed one sampling time backward. The schematic diagram of the most promising RNN structure is illustrated in Figure 6.  
Figure 5: The diagram of workflow for data processing, feature extraction, and modeling [18].