# Artificial Intelligence Algorithms for Treatment of Diabetes
## 2 Methods
### ML with Free-Living Data for Digital Health Technologies in T1D  
In people with T1D, the inability of the body to produce insulin necessitates exogenous insulin administration to regulate the BGC. The advent of CGM devices enabled people with diabetes to monitor their BGC every five minutes and interpret the numerical and graphical information displayed. People with T1D can administer insulin by injections by using injectors or insulin pens or by infusions with insulin pumps to the subcutaneous tissue. While these technological advances improved BGC regulation and insulin delivery, estimating the correct amount of insulin to administer is still a major burden for people with T1D and their care providers. People with T1D make over 100 decisions every day, distracting them from their other activities, increasing the probability of making incorrect decisions, and reminding them of their chronic condition continuously. People have patterns in their behavior that may vary between workdays and weekends, during seasons of the year, and on holidays. Capturing these patterns, in particular meal and physical activity information, provides useful information and enables suggestions for insulin boluses, reminders, and modifications in the target levels of BGC. They can also be used by AID systems (also called artificial pancreas). Determining the habits and behavior patterns of individuals with T1D can increase the time-in-range (keeping BGC in the range of 70-180 mg/dL) and minimize hypoglycemia (BGC < 70 mg/dL) and hyperglycemia (BGC > 180 mg/dL) episodes of people with T1D in free-living. The data used for pattern detection can include BGC measurements reported by CGM devices that measure subcutaneous glucose concentrations, insulin infusions reported by the insulin pump, physiological data reported by wearable devices such as wristbands, and information provided by the individuals, such as meal consumption and amount, and the beginning time and duration of physical exercise. ML with free-living data has many challenges: imbalance in data introduces bias in the classification of daily events such as meal consumption and physical activity. Furthermore, missing values, sensor noise, and outliers reduce the accuracy of ML results. Some of the missing information is caused by interruptions in communication between devices and others by forgetting to enter manual information by the individual with T1D. Hence, data must be preprocessed to reconcile the effects of artifacts, measurement noise, and outliers and impute missing values. The probabilities of meals, 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 that while there are peak times for meals and exercise, their high probabilities of occurrence are spread over time windows ranging from 1 to 3 h.  
The Tidepool dataset is used to illustrate various data preprocessing activities and the efficacy of ML for detecting and discriminating meal and exercise events (including their concurrent occurrence). It includes data from 300 self-collected T1D datasets from people who donated their data for research and the de-identified data were made available for research. Each dataset represents data from one individual with T1D. 50 datasets in this database include CGM sensor-insulin pump recordings and exercise information such as the time, type, and duration of physical activity recorded from either open/closed-loop insulin pump-sensor data. Meal information is reported as the amount of carbohydrates (CHO) consumed in the meal as estimated by the subject (over or underestimation of CHO in meals is common). The subjects with T1D selected for this study used insulin pump-CGM sensor therapy for up to two years, and some of them have lived with diabetes for more than fifty years.