A Deep Learning Approach for Blood Glucose Prediction of Type 1 Diabetes Jonas Freiburghaus and Aı̈cha Rizzotti-Kaddouri and Fabrizio Albertetti 1 Abstract. An essential part of this work is to provide a data-driven long-term relationships between the different values. For instance, it model for predicting blood glucose levels that will help to warn is necessary for the network to be able to capture a correlation be- the person with type 1 diabetes about a potential hypo- or hyper- tween the ingestion of carbohydrates now and a change in the blood glycemic event in an easy-to-manage and discreet way. In this work, glucose level in a near future. we apply a convolutional recurrent neural network on a real dataset This paper is organized as follows: Section 2 presents related work of 6 contributors, provided by the University of Ohio [5]. Our model for glucose prediction, Section 3 formulates the problem of glucose is capable of predicting glucose levels with high precision with a 30- prediction and our contribution, Section 4 details our methodology minute horizon (RMSE = 17.45 [mg/dL] and MAE = 11.22 [mg/dL]), and discuss experimental results. Finally, in Section 5 we summarize and RMSE = 33.67 [mg/dL] and MAE = 23.25 [mg/dL] for the 60- the importance of our contribution and suggest some future work. minute horizon. We believe this precision can greatly impact the long-term health condition as well as the daily management of people with type 1 diabetes. 2 RELATED WORK Predicting blood glucose levels for diabetes (type 1 or type 2) us- 1 INTRODUCTION ing machine learning has gained a lot of attention and has resulted in several methods and applications being proposed recently. They Type 1 diabetes is a disease in which the cells responsible for insulin are however either based on solely measuring the glucose levels or production are destroyed. Because insulin is the hormone that trig- the resulting prediction accuracy is not yet high enough to be consid- gers absorption of glucose within the cells, people with diabetes need ered as a reliable predictor of a potential critical glycemic condition. to monitor their glucose concentration in the blood and readjust it by Several types of regression algorithms can be used, including SVR, frequent insulin injections, following a well-defined medical proto- classic statistical methods such as ARIMA, deep learning neural net- col (e.g., once during the day and once before each meal, to keep works, or even a naive persistence algorithm, to name a few. blood sugar levels within the normal range). The main challenge in Gu et al. [2] propose a personalized smartphone-based non- handling diabetes is the optimization of insulin injections in order invasive blood glucose monitoring system that detects abnormal to avoid hypoglycemia and hyperglycemia. This is complicated by blood glucose levels events by jointly tracking meal, drug and in- the fact that besides insulin intake and diet, glucose levels are also sulin intake, as well as physical activity and sleep quality. It automati- affected by several other factors such as physical activity, lifestyle, cally collects daily exercise and sleep quality, and predicts the current mental state, stress, etc. Despite the various accomplishments made blood glucose level of users, together with manual records of food, in continuous diabetes monitoring (a.k.a. continuous glucose moni- drug and insulin intake. It needs re-calibration using CGM devices toring, CGM), such methods remain invasive. Furthermore, they are once every three weeks and is based on multi-division deep dynamic only able to provide the glycemic state at a given time, when the recurrent neural network framework. Plis et al. [6] propose a solution insulin level may already be unacceptable (too high or too low). A that uses a generic physiological model of blood glucose dynamics proactive detection could therefore dramatically improve the daily to generate features for a SVR model that is trained on contributor handling of diabetes by the patients themselves. specific data. It is shown that, the model could be used to anticipate This work presents an approach based on deep learning algorithms almost a quarter of hypoglycemic events 30 minutes in advance, how- for predicting glucose levels in the future (30-minute and 60-minute ever the demonstrated corresponding precision is 42%. Contreras et horizons). Our work is based on the architecture of a recurrent neu- al. [1] present an alternative approach to glucose levels prediction, ral network (CRNN) from [3] and proposes certain variants, such as based on previous studies that incorporated medical knowledge into a multi-step predictions, regression model using blood glucose level grammar aimed to build expression for glucose that considered previ- data for each person every 5 minutes, and the inclusion of other data ous glucose values, carbohydrate intake, and insulin administration. such as basal insulin, bolus insulin, and meal values. They extend the previous research to investigate a novel and com- The goal of using a CRNN architecture is twofold. (1) Convolu- plementary approach that uses symbolic regression through gram- tional layers act as filters and automatically learn to detect the fea- mar evolution to determine an approximate glucose levels and fluc- tures of interest for prediction. They are also particularly convenient tuations using personalized blood glucose predictive models. In the for analyzing time series with little signal processing required. And same order of topic, we note the work in [4]. It also contains a com- (2), recurrent neural network are well-known for the capacity to learn parison with a prediction using latent variable with exogenous input 1 HES-SO University of Applied Sciences and Arts of Western Switzerland, (LVX [9]) model, in this model bolus insulin and meal are included email: aicha.rizzotti@he-arc.ch in the predictor matrix X but in this work only meal information is Copyright © 2020 for this paper by its authors. Use permitted under Creative Commons License Attribution 4.0 International (CC BY 4.0). added . We can see that the RMSE for a prediction horizon of 60 min is not used at test time as it could lead to a data peek. Meaning the for clinical data, varies from 37.02 to 35.96 [mg/dL]. In [3], they use predictions would be contaminated by future values. a deep learning architecture for predicting 30-minute and 60-minute The CRNN model target values are based on the following equa- horizons on both real and simulated patients. For real patients and tion: a 30-minute horizon, they report an RMSE of 21.07 [mg/dL]. How- ever, only a few approaches have used deep learning algorithms for yt+L = bgt+L − bgt , for L = 1, 2, . . . , 12 (1) CGM on clinical data and more specifically for this dataset provided by the University of Ohio [5]. where bgt is the blood glucose value at time t, L is the lag value in timesteps for the horizon, and y the label to predict, that is the 3 Glucose Prediction differentiated value of the blood glucose level. The aim of this work is to predict glucose levels in advance in or- For instance, if the blood glucose level is 80 mg/dL at the cur- der to avoid situations of hyperglycemia or hypoglycemia, as well rent time and 60 mg/dL 30 minutes later, the label for a prediction as others negative effects on the health. For instance, chronic hyper- horizon of 30 minutes at the current time would be −20 mg/dL. glycemia may induce fatigue and vision problems among others. For Respectively, as the model does not predict directly the blood glu- that purpose, we created a model capable of predicting the glycemia cose level but only the difference from the last known value. The of type 1 diabetes, where values must be as accurate as possible. In predicted blood glucose level is obtained with the following equa- this context, the metrics are the RMSE and the MAE. The smaller tion: these values, the more reliable the model. The real gain for a pa- tient is to be able to make decisions at any given time considering bg b t+L = bgt + ŷt+L , for L = 1, 2, . . . , 12 (2) the prediction of future values, and possibly avoid glycemia-related discomforts while minimizing intrusive methods. where bgt is the blood glucose value at time t, bg b t+L is the predicted blood glucose level at time t + L, ŷt+L is the predicted 4 METHODOLOGY blood glucose level difference at time t with lag L, L is the lag value in timesteps for the horizon, and y the label to predict. 4.1 Approach Our approach can be summarized by the following steps: It is important to note that the CRNN only outputs the values ŷt+L . The model is capable of giving a prediction for each 5 minutes 1. Data importation prediction horizon up to 60 minutes that is 5, 10, ..., 60 minutes. This 2. Data preprocessing feature may give valuable information to a user and thereby improve 3. Implementation of the CRNN prediction model with multi-step their blood glucose level control. An example of such a prediction is forecasting given in Fig. 5. 4. Training, testing and tuning on selected features The overall architecture of the CRNN is based on [3] and de- 5. Delivery of the forecasted blood glucose levels scribed in Fig. 1. The input signals time series are fed into a CNN for extracting relevant features. The purpose of the pooling layers Data importation involves loading, merging, and aligning values is to gradually reduce the spatial dimension while keeping only the from multiple sources under the same time scale. The selected fea- highest values included in the pooling window. Then, these features tures are basal/bolus insulin, carbohydrates, and blood glucose levels. are fed into an RNN layer to model the relationships over time. Fi- In the preprocessing step, all variables must have measurements nally, a dense neural network is used as a last layer for regressing the carried over at the same time. This requires the use of subsampling desired target. or oversampling methods and, corollary, defining imputing methods. Linear interpolation is used for the glucose level on the training set to resample the time series at a frequency of 5 minutes. The others features may be imputed with null values when required, as their na- ture is sparse. We can also use domain-specific functions, such as an equation describing the absorption rate over time for carbohydrates. The preprocessing steps are summarized by : 1. Save all the blood glucose timestamps 2. Resample the features to a time delta of 1 second 3. Forward fill the missing values by using the last available values 4. Fill the left missing values with 0 5. Resample the features to a time delta of 5 minutes 6. Smooth each feature with a 1D Gaussian filter over a window con- taining the past 2 hours of data Figure 1. A multi-layer CRNN composed of convolutional layers, pooling layers, an RNN network, and a dense neural network We use the saved timestamps at preprocessing step 1 to generate the results at the same timestamps as the measured values. Linear interpolation is used during the training process to impute The training of a model is done on a contributor-basis, that is one the missing values. This allows to have more data points for the model is trained per contributor. The reason is that each glucose re- model to be trained on. However, we should note that linear inter- sponse is individual, and a one-population model does not seem rea- polation is not ideal for big gaps of missing values. The interpolation sonable for CGM. 4.2 Experimental Results 4.2.1 Dataset n Our results reported in this work are based on the OhioT1DM dataset 1X M AE = |ŷi − yi | (4) [5]. For each contributor a train set as well as test set are provided. n i=1 One model only is pretrained on the data from the 6 contributors of 2018. Then for each 6 data contributor of 2020 transfer learning is applied, resulting in one trained model per contributor. The reported results are based on the following signals: glucose The first observation is the errors systematically increase for each level, basal insulin, bolus insulin, and meal for 6 data contributors contributor over time. It is not surprising that the larger the prediction (540, 544, 552, 567, 584, and 596). While more signals were avail- window, the larger the error in general grown up. able, we decided to use only these signals. Indeed, we performed A comparison between contributors was also performed (Fig. 2 several tests with the complete dataset and the preliminary results and Fig. 3). As we can see, for example with the contributor 596, indicated better results with a limited set of features. the prediction curve for 30 minutes and 60 minutes follows the real The use of a sliding window consisting of the last 2 hour data, curve with an RMSE = 13.34 and MAE = 9.08 [mg/dL], and RMSE resulting in 24 data points is based on [3]. Cross- and/or auto- = 27.74 and MAE = 19.13 [mg/dL]. These specific curves are also correlation may provide a good starting point to find a reasonable detailed in Fig. 4. sliding window size. Of course, the computing complexity must be taken into consideration depending on the targeted deployment hard- ware. 4.2.2 Architecture and learning process The detailed architecture of the CRNN is presented in Table1. Layer description Output dimension Convolution 1D (Batch size, 24, 8) Max pooling 1D (Batch size, 12, 8) Convolution 1D (Batch size, 12, 16) Max pooling 1D (Batch size, 6, 16) Convolution 1D (Batch size, 6, 32) Max pooling 1D (Batch size, 3, 32) LSTM (Batch size, 64) Dense (Batch size, 256) Dense (Batch size, 32) Dense (Batch size, 12) Figure 2. RMSE-30 vs RMSE-60 horizons for the 6 contributors of 2020 Table 1. Neural network layers and output shapes The model is pretrained on batches of size 1024 over 1000 epochs, with an RMSProp optimizer. The learning rate is initially set to 0.001 and is reduced with a factor of 0.1 when the model does not progress after 3 epochs. Early stopping is used similarly with a patience of 50 epochs in order to regularize the model. The last model’s weights with the lowest validation loss are then restored. For each data contributor of 2020 the pretrained model is loaded and trained similarly as the pretraining stage. With the only differ- ence that the learning rate is reduced with a patience of 15 epochs and that one model is saved for each contributor. 4.2.3 Results The RMSE and the MAE are calculated for the six contributors using the following equations. v u n u1 X RM SE = t (ŷi − yi )2 (3) n i=1 Figure 3. MAE-30 vs MAE-60 horizons for the 6 contributors of 2020 where ŷi is the predicted value, yi the truth value and n the number of observation. model. It forecasts the blood glucose level by using the last know value. ŷt+L = bgt−1 , for L = 1, 2, . . . , 12 (5) Metrics (1) Li’s CRNN (2) BASELINE (3) CRNN Prediction horizon (mg/dL) Overall MAE NA 18.13 ± 0.00 11.22 30 RMSE 21.0.7 ± 2.35 25.76 ± 0.00 17.45 MAE NA 30.70 ± 0.00 23.25 60 RMSE 33.27 ± 4.79 42.00 ± 0.00 33.67 Table 2. Comparison of different algorithms: (1) Li’s CRNN from [3], (2) baseline with persistence forecast (where the previous value is predicted), and (3) the proposed CRNN. Let us note that (1) uses different data (not publicly available) than from (2) and (3). With the hypothesis of a hypo-glycemia starting below 70 mg/dL and a hyper-glycemia starting above 150 mg/dL, we believe that our model delivers relevant and actionable results for real patients. In our opinion, a RMSE of 17.45 mg/dL for a 30-minute horizon indicates that data-driven decisions could be made in regard to avoiding hypo or hyper-glycemic related events. 5 CONCLUSION In this paper we described a model for predicting future blood sugar levels of people with type 1 diabetes. A CRNN approach was pro- posed with the advantages of using only 4 different signals and very Figure 4. Example of prediction results of contributor 540, for 30 and 60 little signal processing. The evaluation was performed using RMSE minutes and MAE metrics, with different horizons and on multiple contribu- tors. The results were compared with different algorithms.The results report low error rates given the problematic of glucose prediction, The evaluation of the prediction from the contributor-side can be and in our opinion could be considered for real-world implementa- performed by a multi-step prediction (as illustrated in Fig. 5). Predic- tion. Yet, several research tracks remain to be explored. For instance, tion is made through one forward pass of a horizon of the last 2 hours testing additional features that can influence blood sugar levels such data and outputs the horizon for the next hour represented by the or- as stress or illness. We can also think of extracting manual features ange curve. In the given example, the model seems to have predicted from the given signals with signal processing methods, and defining well the tendencies. domain-specific imputation methods, such as for the absorption of carbohydrates over time. It would be also interesting to further per- sonalize predictions as suggested in [7]. Another direction could be to use reinforcement learning approaches for the insulin recommen- dation, such as in [8].Those self-learning approaches are adaptable and personalize the daily insulin values to ensure glucose control, despite inter and intra-patient variability. ERRATUM During the making of the camera ready version, we found an error in the preprocessing stage thanks to the great reviews. The missing val- ues were treated using a linear interpolation during the testing of the model. Thereby the predictions were contaminated by future values. This error was corrected by removing the interpolation and dealing with missing values as explained in this paper version. Figure 5. Multi-step prediction of one forward pass Code source It is available at https://github.com/JonasFreibur/BLGP-HES-SO A comparison of our approach with other algorithms is summa- rized in Table 2. We notice that the RMSE of our work at horizon 30 ACKNOWLEDGEMENTS is smallest and at 60 minutes similar to [3]. Let us highlight that in The authors would like to thank the HES-SO for funding this re- (1) the database is different. The persistent algorithm is the baseline search. REFERENCES [1] Iván Contreras, Silvia Oviedo, Martina Vettoretti, Roberto Visentin, and Josep Vehı́, ‘Personalized blood glucose prediction: A hybrid approach using grammatical evolution and physiological models.’, PloS one 12.11, (2017). [2] Weixi Gu, Yuxun Zhou, Zimu Zhou, Xi Liu, Han Zou, Pei Zhang, Costas J Spanos, and Lin Zhang, ‘Sugarmate: Non-intrusive blood glu- cose monitoring with smartphones.’, Proc. ACM Interact. Mob. Wearable Ubiquitous Technol, (2017). [3] Kezhi Li, John Daniels, Chengyuan Liu, Pau Herrero-Vinas, and Panteli Georgiou, ‘Convolutional recurrent neural networks for glucose predic- tion.’, EEE journal of biomedical and health informatics, (2019). [4] Chengyuan Liu, Josep Vehi, Nick Oliver, Pantelis Georgiou, and Pau Herrero, ‘Enhancing blood glucose prediction with meal absorption and physical exercise information.’, arXiv preprint arXiv:1901.07467, (2018). [5] Razvan C. MARLING, Cindy et BUNESCU, ‘The ohiot1dm dataset for blood glucose level prediction.’, KHD@ IJCAI, (update 2020). [6] Kevin Plis, Razvan Bunescu, Cindy Marling, Jay Shubrook, and Frank Schwartz, ‘A machine learning approach to predicting blood glucose levels for diabetes management. in proceedings of aaai workshop on modern artificial intelligence for health analytics.’, AAAI Press, 35–39, (2014). [7] Qingnan Sun, Marko V Jankovic, João Budzinski, Brett Moore, Peter Diem, Christoph Stettler, and Stavroula G Mougiakakou, ‘A dual mode adaptive basal-bolus advisor based on reinforcement learning.’, IEEE journal of biomedical and health informatics, 23(6), 2633–2641, (2018). [8] Qingnan Sun, Marko V Jankovic, and Stavroula G Mougiakakou, ‘Rein- forcement learning-based adaptive insulin advisor for individuals with type 1 diabetes patients under multiple daily injections therapy’, in 2019 41st Annual International Conference of the IEEE Engineering in Medicine and Biology Society (EMBC), pp. 3609–3612. IEEE, (2019). [9] Chunhui Zhao, Eyal Dassau, Lois Jovanovič, Howard C Zisser, Fran- cis J Doyle III, and Dale E Seborg, ‘Predicting subcutaneous glucose concentration using a latent-variable-based statistical method for type 1 diabetes mellitus’, Journal of diabetes science and technology, 6(3), 617–633, (2012).