scieee AI-readable full text Open interactive document viewer

Glucose classification and prediction system with neural networks

Varela Lorenzo, Alejandro; Delgado Gutierrez, Alvaro

Abstract

Glucose levels prediction is a difficult task commonly faced by people with diabetes, a chronic health condition that affects how a human body synthesizes food. People with diabetes must have an exhaustive control of the levels of sugar in the bloodstream in order to manage insulin intakes, a procedure that is usually done manually and without enough accuracy. Levels of glucose in a human body depends on a lot of different factors, so the risk of doing miscalculations is always taken by the patient. Nowadays, using new technologies such as Artificial Intelligence (AI) or Machine Learning (ML), these calculations can be supported and eased by the application of prediction systems. The field of AI and ML is very large, providing scientists with several different tools to create forecasting algorithms. During this project, we are going to focus on the creation and use of Neural Networks (NN) for glucose level prediction. To create this systems, we are exploring different types of Neural Networks (NN), ranging from regular numeric NN to graphic NN applications, which are vastly known in the world of data scientists. However, these algorithms are always a difficult and hidden process for the real users, diabetes patients, so in order to make a higher impact on people affected by this disease, we will create an online application that will share all the power of NNs with the final patients, using a clear and intuitive user interface. In the meantime, patients will collaborate on the NN training process, as long as data provided by those using the application will allow us to develop a more heavily trained NN, thus improving its effectiveness in glucose levels forecasting. Referring to the numerical NN and according to the results, we can state that their performance for 30 and 60 minutes prediction is quite accurate and, for 90 and 120 minutes prediction, it throws promising results. Instead, for the graphical NN, even though the approach is interesting and the studies are showing us that the technology is very powerful, it needs much more investigation until we get good results.

Full text

Universidad Complutense de Madrid Facultad de Informatica Glucose classification and prediction system with Neural Networks Final Degree Project Authors: Alejandro Varela Lorenzo Alvaro Delgado Gutierrez Advisor: J. Ignacio Hidalgo June 2020 Contents 1 Summary 3 2 Introduction 5 2.1 Background ............................ 5 2.2 Goals................................ 7 2.2.1 Development of glucose prediction models . . . . . . . 7 2.2.2 Website service . . . . . . . . . . . . . . . . . . . . . . 7 2.3 Work-plan............................. 7 3 State of the art 9 4 GlucNet 15 4.1 Devices .............................. 15 4.2 Datasources............................ 16 4.3 Data preprocessing . . . . . . . . . . . . . . . . . . . . . . . . 17 4.3.1 Study of the data-set . . . . . . . . . . . . . . . . . . . 17 4.3.2 Datafilling ........................ 18 4.3.3 Normalization . . . . . . . . . . . . . . . . . . . . . . . 19 4.3.4 Data to be supervised . . . . . . . . . . . . . . . . . . 19 4.3.5 The data frame is prepared . . . . . . . . . . . . . . . 21 4.4 Glucose forecasting with numerical data . . . . . . . . . . . . 21 4.5 Glucose forecasting with wavelets images . . . . . . . . . . . . 24 4.5.1 Introduction to Digits . . . . . . . . . . . . . . . . . . 25 4.5.2 Creating wavelet images . . . . . . . . . . . . . . . . . 25 4.5.3 Training with NVIDIA Digits . . . . . . . . . . . . . . 27 4.6 GlucNetWebsite ......................... 28 4.6.1 Connection with database . . . . . . . . . . . . . . . . 33 5 Experimental Results 34 5.1 Metrics............................... 34 5.2 Results............................... 35 5.2.1 First execution with Patient 1 . . . . . . . . . . . . . . 35 5.2.2 Descriptions of the results . . . . . . . . . . . . . . . . 36 5.2.3 Train with Feed Forward . . . . . . . . . . . . . . . . . 37 5.2.4 Train with LSTM . . . . . . . . . . . . . . . . . . . . . 45 5.2.5 Train with NVIDIA Digits . . . . . . . . . . . . . . . . 53 1 6 Conclusions and Future work 55 6.1 General conclusions . . . . . . . . . . . . . . . . . . . . . . . . 55 6.2 Futurework............................ 56 7 Alejandro Varela work 58 8 Alvaro Delgado work 60 9 Acknowledgment 62 10 Bibliography 63 2 1. Summary Abstract Glucose levels prediction is a difficult task commonly faced by people with diabetes, a chronic health condition that affects how a human body synthesizes food. People with diabetes must have an exhaustive control of the levels of sugar in the bloodstream in order to manage insulin intakes, a procedure that is usually done manually and without enough accuracy. Levels of glucose in a human body depends on a lot of different factors, so the risk of doing miscalculations is always taken by the patient. Nowadays, using new technologies such as Artificial Intelligence (AI) or Machine Learning (ML), these calculations can be supported and eased by the application of prediction systems. The field of AI and ML is very large, providing scientists with several different tools to create forecasting algorithms. During this project, we are going to focus on the creation and use of Neural Networks (NN) for glucose level prediction. To create this systems, we are exploring different types of Neural Networks (NN), ranging from regular numeric NN to graphic NN applications, which are vastly known in the world of data scientists. However, these algorithms are always a difficult and hidden process for the real users, diabetes patients, so in order to make a higher impact on people affected by this disease, we will create an online application that will share all the power of NNs with the final patients, using a clear and intuitive user interface. In the meantime, patients will collaborate on the NN training process, as long as data provided by those using the application will allow us to develop a more heavily trained NN, thus improving its effectiveness in glucose levels forecasting. Referring to the numerical NN and according to the results, we can state that their performance for 30 and 60 minutes prediction is quite accurate and, for 90 and 120 minutes prediction, it throws promising results. 3 Instead, for the graphical NN, even though the approach is interesting and the studies are showing us that the technology is very powerful, it needs much more investigation until we get good results. Keywords Diabetes Mellitus, Glucose Levels Prediction, Neural Networks, Forecasting, Online service, Machine Learning, NVIDIA Digits. 4 2. Introduction 2.1. Background Diabetes is a chronic disease that is irreversible and affects the normal transformation of sugar in energy. It occurs when blood glucose, also called blood sugar, is too high in the bloodstream. Insulin, a hormone made by the pancreas, helps glucose from food get into the cells to be used for energy. Sometimes, the body doesn’t make enough insulin or doesn’t use insulin correctly, so glucose stays in the bloodstream and doesn’t reach the cells. Over time, having too much glucose in the blood can cause several health problems. We can differentiate two main types of diabetes: •T1DM (type 1) This type is the less common within the patients of diabetes, a tenth of total. It is an autoimmune illness that attacks the pancreatic cells which generate insulin, making them dysfunctional. Thus, the patients need to supply themselves with daily doses of insulin that replace those the metabolic system should generate. •T2DM (type 2) With diabetes type 2, the metabolic system is able to generate insulin, but the immune system creates resistance to it, resulting in a similar outcome as in T1DM. Anyways, people with T2DM do not always need to supply themselves with daily doses of insulin. Normally, it is enough if they have a healthy routine and diet. This type of diabetes appears along the lifetime, and can be prevented or delayed with a healthy lifestyle (exercise, healthy diets...). To maintain normal levels of glucose, the patients need to have control of those levels every time, taking into account the physical effort, diet and other factors such as alcohol intakes, level of stress, etc. To measure the levels of glucose it is usual to have a manual glucose meter or a continuous glucose monitoring system. This is a tedious task that is done on a daily basis by the patient and that provokes an extra stress. Patients need to know the glucose level to decide if they need to take a corrective action, such as injecting insulin or eating some food. To help with this 5 routine, new methods are being investigated. One of them is the prediction of glucose levels, which could potentially allow patients to anticipate when there is a risk of hypoglycemia or hyperglycemia. However, glucose levels prediction is a extremely difficult task because of the great amount of factors that are involved. Furthermore, predictions must be really accurate, since a wrong dose of insulin, taken from a wrong prediction, can cause health problems on the patient. This field of study is not new. Previously, numerous techniques have been tried for glucose forecasting. The greatest aim of this techniques is to achieve a permanent solution for diabetes, such as the development of an ”artificial pancreas”. Figure 1 summarizes the different automatizing approaches for diabetes [1]. Figure 1: Comparison of automatizing on current methods of diabetes treatment [1] Through an artificial pancreas with an advanced prediction system along with measurement instrument such as a continuous glucose monitor, it could be possible to automate the insulin injection process in the same way as the pancreas of a healthy person works. Some of the techniques used for this prediction model are: Genetic Programming, Random Forest Regression, K-Nearest Neighbors or Grammatical Evolution [1] and, of course, Neural Networks [2]. 6 2.2. Goals 2.2.1. Development of glucose prediction models The main goal of the project is to forecast the level of glucose that diabetes patients are going to have in the next 30, 60, 90 or 120 minutes based on their previous data. With this data, we’ll train different versions of models to obtain as many results as possible. Thus, we can make comparisons between different models, and understand which parameters and configuration are the best for the glucose prediction. This will be a long-term study in the python environment to have a consistent model to train and predict glucose values. 2.2.2. Website service Once we obtain a precise model with an optimal configuration of the data, we want to develop a website where any diabetes patient can access to make their glucose predictions with an intuitive interface. This application must be as simpler as possible to the user. With this platform, not only we provide the user with a prediction of its glucose levels, but also, if the user authorize it, we use his data to train our models. All the results and training will be saved in a database, that we will need to create and adapt to the current AbsysGroup database. Thus, there will be a connected system between our project and the previous one. Hence, the main goal is to create the website system that will cover and be the final image of the models development and the machine learning work. 2.3. Work-plan Our work-plan for the creation of GlucNet will be separated in the following stages: •Study the information related to diabetes and the correlation between the different factors and the glucose level •Get in touch with the data structures •Pre-processing the data 7 •Start with the first neural network (NN) training •Try different parameters and types of NN •Implement the website •Join the algorithm and the website •Connect the database with the website The rest of this document is organized as follows. Section 3 reviews previous approaches on glucose prediction by Neural Networks. Section 4 explains the whole process of the project including: •Explanation the data format in sections 4.1 and 4.2. •Data pre-processing task in section 4.3. •Creation and training of numerical NN in section 4.4. •Adaptation of the data for the graphical NN and its training in Nvidia Digits in section 4.5. •Implementation of the website and its database in section 4.6. Afterwards, section 5 explains the metrics used for the results and discuss the results from the different NN. Finally, on Section 6, we state our conclusions from the project and propose some future work to keep improving the project. 8 4. GlucNet GlucNet is an online service for glucose classification and prediction that is based in Neural Networks implemented in Python. The whole process to get the final product includes: •Working with the data and preparing it to every different scenario. •Creating the neural nets that will work in the website. •Exploring a new approach on glucose prediction and classification based in Graphic NN. •Creating a website where NN will be supported. 4.1. Devices The following sensors are used to measure the glucose and insulin values, physical activity and food intakes: •Free Style Libre-Abbott •Minimed Medtronic CGM •Medtronic Insulin Pump •Roche Insulin Pump •Fitbit Ionic •Notes from patients Please note, that not all the patients have all the data because we were not able to recover all the items. Using this devices, we recorded the following data: •Interstitial glucose •Notes of estimated carbohydrate units ingested, taken by each patient. 15 •Insulin injected using an insulin infuser device from Medtronic and/or Roche, which registers injections of both basal and bolus insulin every five minutes. •Burned calories and steps •Other information 4.2. Data sources In this section we will show the two different sources of data we got to work with. Our main source of data and the one that is going to guide the study are the files containing data from Patients of the Hospital Universitario Pr´ıncipe de Asturias de Alcal´a de Henares in Madrid, from June 13th, 2018 to, July 17th, 2019. Column Meaning Measuring Device Note Basal Rate (U/h) Basal rate Medtronic Pump Every 5 min if it is ok Bolus Type Bolus type Medtronic Pump anytime, Bolus Volume Delivered (U) Bolus Units Medtronic Pump anytime, BWZ Carb Ratio (U/Ex) Insulin-to-carbohydrate Ratio Medtronic Pump anytime, BWZ Carb Input (exchanges) Amount of carbohydrates Medtronic Pump anytime, Sensor Glucose (mg/dL) The sensor glucose value CGM Medtronic Every 5 min if it is ok Hora Time Anyone Calorias Calories from Fitbit Fitbit anytime, Ritmo Cardiaco HR from Fitbit Fitbit anytime, Estado Sleeping state from Fitbit Fitbit anytime, Pasos Steps from fitbit Fitbit anytime, Hist´orico glucosa (mg/dL) Automatic glucose level Freestyle Every 15 min if it is ok Glucosa le´ıda (mg/dL) Manual glucose level from FreeStyleLibre Freestyle anytime, Insulina de acci´on r´apida sin valor num´erico Bolus Mark Freestyle anytime, Insulina de acci´on r´apida (unidades) Bolus units Freestyle anytime, Alimentos sin valor num´erico Food intake Freestyle anytime, Carbohidratos (raciones) Food intake units Freestyle anytime, Insulina de acci´on lenta sin valor num´erico Slow action insulin timestamp Freestyle anytime, Insulina de acci´on lenta (unidades) Units of slow action insulin Freestyle anytime, Notas Notes Freestyle anytime, Glucosa de la tira (mg/dL) Glucose Meter from FreeStyle Libre Freestyle anytime, Cetonas (mmol/L) Ketones from Freestyle Libre Freestyle anytime, Insulina comida (unidades) Insulin units Freestyle anytime, Insulina correcci´on (unidades) Units from corrector bolus Freestyle anytime, Insulina cambio usuario (unidades) Daily insulin units Freestyle Low fidelity Hora anterior Time change Freestyle anytime, Hora actualizada Time change Freestyle anytime, Sensor Calibration BG (mg/dL) Glucose calibration Extern glucometer anytime, BG Reading (mg/dL) Glucose calibration Extern glucometer anytime Table 1: Meaning of each parameter from Alcal´a de Henares patients datasets 16 Table 1 shows the variables stored on the csv file with their meanings, the devices from where data was retrieved, an explanation and notes on the frequency of acquisition and/or any other particularity. We have access to 15 data-sets of different patients from this hospital, each one with around 3500 rows of data along with the timestamps. Our second source of data are the files from 6 different patients from Ohio’s Hospital. These csv have very different columns and almost all of them do not have enough data to be useful (less than 25% of the total amount of rows in the data-set). The columns that will have more importance for us are ”basaleventvalue”, ”accelerationeventvalue” and ”Glucose leveleventvalue”. From the first two we can get the equivalent Basal Rate (U). 4.3. Data preprocessing As in every data-mining and machine learning project, the first task after analysing the data is preparing it to be used by the algorithm. In this glucose prediction project we are working on data from single individuals based on time series. 4.3.1. Study of the data-set Firstly, when we take a look at the main source of data (data from Patients of the Hospital Universitario Pr´ıncipe de Asturias de Alcal´a), we noticed that the majority of the columns do not provide useful information as they have repeated information or not to many values to work with. This columns that are not useful or have too much ”not assigned” (NaN) have to be deleted. Furthermore, as we are working with data based on time, more specifically every 5 minutes, it is important to treat the data as a time series. The column of time is not only a variable, but also the value that specifies the order in which the data is related. To specify this order we use the time as an index, making it easier to train the data. In the case of the Basal Rate, it is valued as units per hour so it is necessary to divide every value in this column by 12, resulting in units per 5 minutes. Figure 2 shows the result of dropping the columns from the data-set. 17 Figure 2: Resulting data-set after dropping columns Furthermore, there is another data source, the Ohio’s Hospital, which has very different columns compared to our previous source. As we want to create an unified model that can support different data sources, we need to adapt this data-set to our main structure. As we did with the other data-sets from Principe de Asturias Hospital, we need to drop all the columns that do not have sufficient information. In this case, the only columns that have good and enough data to train are the levels of glucose and the Basal Rate. This data-set is also organized in 5 minutes timestamps. 4.3.2. Data filling Once the data frame has the proper columns and is converted into a time series, the next step is to create data for the non assigned values, this task is commonly known as data-filling. In this case, it was necessary to use two different types of data-filling, interpolated and bfill. The interpolate function fills the values between 2 different numbers making use of a lineal function, and the bfill function simply copies the data from the last seen value in all subsequent missing values. We use the interpolate function to fill the intermediate gaps in the numerical columns such as the levels of glucose to obtain reasonable new values. Using interpolate for the basal rate won’t be accurate since the values are taken every hour. in this case, we simply copy the value for 5 minutes in every hour. Finally, for the steps and calories columns it is not necessary to 18 perform any data-filling. 4.3.3. Normalization On the machine learning work, every type of column usually have very different ranges of values which are not homogeneous. Normalization is the best solution to have similar ranges to work with. It is sometimes required to normalize the data for training with some neural networks such as Keras. In the case of the numeric neural nets, we use the MinMax scaler between 0 and 1 because the data-set does not contain negative values. Instead, when using graphic neural networks, we apply the Zscore normalization to represent the data graphically and train the algorithm in Digits. We apply this different method for the graphical data because with MinMaxScaler the graphics for the columns with low values did not show the range properly. Zscore applies one normalization for each type of data. 4.3.4. Data to be supervised Once we have all the columns with the right data, we need to convert the data-set in a supervised data-set. This is a required task because we need all the data related to each prediction in each line. More deeply, for each row, which target is 30, 60, 90 or 120 minutes prediction, we need the data that affects directly to the prediction. As we see in the Figure 3, it is always necessary to have the values of glucose and basal rate from the previous 120 minutes and the data of the basal rate from 30 to 120 minutes in the future. To do this, we copy the glucose and basal rate data of the previous 24 rows and the data of the future 6-24 rows in each row. In Figure 4 the function that performs it is shown. The function that converts the data frame to supervised data, using the function on Figure 4, depends on the type of prediction you want to perform, having as parameter the minutes for the prediction. 19 Figure 3: Explanation of variables needed for supervised learning Figure 4: Function that prepares the data for supervised learning 20 Taking this argument, the function calculates how many columns are needed to create the supervised data-set: always 24 columns for the past 120 minutes of glucose and 24 columns for the last 120 minutes of insulin intake. It also creates columns for the future insulin intakes; this is useful because it is one of the main reasons why glucose level can fall. It is also needed to crop the data-set since, at the beginning, we do not have past values for insulin, and at the end, we do not have future values. 4.3.5. The data frame is prepared After this, the data frame is already prepared to work with neural networks, but some other tasks could be done to improve the performance of the algorithm. One of them is the Data augmentation, this means creating totally new data based on given data frames. In the Medicine-AI field this can be really useful since one of the main problems is the lack of data. Creating new data makes possible to work with more examples, thus creating a more accurate neural net. 4.4. Glucose forecasting with numerical data In this project we are dealing with a multi-variable regression problem, as the goal is to predict the glucose that a diabetes patient can have in a determined time. Through the data conversion to time series, we can transform the data to have a supervised data-set. This means that the algorithm is trained with the data of the patient before the consultation of the level of glucose, and with the data of the patient after that consultation (figure 5). Due to some patients have less data parameters than others, we had to divide them and create different models depending on the parameters they have. Thanks to this, we can evaluate the training performance depending on the type of data, and get some conclusions. 21 Figure 5: Columns of the supervised data-set Hence, these are the types of model depending on the parameters of each patient: •Patients with insulin and basic values (3 patients) –Glucose –Steps –Heart rate –Calories –Basal rate •Patients with only basic values (10 patients; the patients with insulin values are also valid for this training) –Glucose –Steps –Heart rate –Calories •Patients from Ohio and 3 from Alcal´a de Henares that contains: –Glucose –Basal rate •All the patients, but only with the glucose values. –Glucose 22 The initial model we chose to train the data was a simple feed forward declared with Keras to test if the supervised data-set generated was well configured. Once checked that the data pre-processing was properly prepared, we configured the first type of neural network to train and test all the patients. The function that creates this NN can be seen on Figure 6. Figure 6: Creation of the FF model This initial neural network is configured with the input layer (data supervised), one hidden dense layer with a hyperbolic tangent activation function that expects rows of data with the number of columns of the supervised data-set, and one output dense layer with one node. •190 epochs •Tahn activation function •Adam optimizer •Input shape: (1, number of columns of the data-set) •Mean absolute error as loss function After testing the models mentioned with the feed forward neural net, the next step was to modify the configuration of the model to see if it was possible to improve the results. There are different variations of neural networks according to the type of data. Due to data-sets are time series, we decided to test configurations with a type of recurrent neural network called LSTM (Long short-term memory). 23 These types of neural networks were created to give a solution to the short-term memory. They have an internal mechanism called gates that can regulate the flow of information. These gates can learn which data in a sequence is important to keep or throw away. By doing that, it can pass relevant information down the long chain of sequences to make predictions. This is the configuration of the new neural net: model = Sequential () model . add (LSTM( number columns , input shape =(1 ,number columns ) , a ct iv at io n =’ relu ’ , r etu rn seq uence s = True )) model . add ( Flatten ( ) ) model . add ( Dense (1 , ac ti va tio n =’tanh ’ ) ) model . compile ( l o s s =’ mean absolute error ’ , optimizer =’Adam’ , metrics =[”mse ” , ’ accuracy ’ ] ) 4.5. Glucose forecasting with wavelets images For this different approach of glucose forecasting, we face a classification problem: we are going to predict whether the patient is going to have a hypoglycemia episode in the next period based on images with data from 6 to 24 hours. These images are divided in two classes. Taking a period from 6h to 24h (depends on the model), we will seek in the following period for values of glucose below 70 mg/dL. If that period has at least one value below 70 mg/dL, it will be considered as a Hypoglycemic period, otherwise, it will be considered as a Normal period. This type of training with images is something totally new in the field of diabetes-AI, so it will be an experimental work. To prepare the data for this section some pre-processing tasks are avoided such as making the data set supervised. To support the neural nets and its training we are going to use Nvidia Digits, a platform that eases the work with images. 24 Figure 11: Training page –If the .csv does not have values of glucose for every 5 minutes, the missing fields need to be empty in order to recognize it as NaN. –Numbers need to use decimal dot. •User page: On the user screen, shown in Figure 12, the user personal information is displayed. This includes: name, surname, email and username. Also, we display a small summary of the last 5 training results that the user has performed. •Results page: This page is the one that comes after training is performed. It shows the results of the training and prediction with the data uploaded. The information displayed, as seen in Figure 13, is the RMSE (Root Mean Squared Error), the Clarke error grid along with the number of points on each section and a graph that compares the real target with our prediction. We also make a single prediction for the last 120 minutes in the data-set, simulating how the algorithm would work in real life usage. 31 Figure 12: User page Figure 13: Results page 32 4.6.1. Connection with database Given the fact that, in this website, the user creates new models, uploads data and the system generates results, it was necessary to implement a database to keep stored all this information. Furthermore, due to there was an implemented database from other final degree project that was functioning, we needed to follow a established syntax to create a database which was adaptable to the existing one. The needed tables to incorporate to the system are the following: •User tables that Django creates automatically. We are using the table ’auth-user’ for users management. •Files tables where the system keeps the uploaded files of the user, with the user id. •Models table that saves the type of model, the last user that trained it, whether it is personal or general and the model RMSE. •Results table to keep the results of a prediction (RMSE, zones of the clarke graphic, user id). To create the database, we used MySQL Workbench and Server, which are really intuitive to manage the different components of the data structure. 33 5. Experimental Results 5.1. Metrics In order to measure the efficiency and behaviour of the model, we are going to use the following metrics: •Clarke error grid This Clarke graphic visualizes black points that represent the real test target (axis x) and the predicted values (axis y). In a first instance, the closer the points are allocated around the diagonal (which means that predictions are equals to real test set), the more precise the model will be. This Clarke graphic displays different zones: A,B,C,D,E. These zones represent the validity of the precision. So the target of the model is to have most of the point within the zones A and B, and as few points as possible in the zones C, D and E. An example of an empty Clarke Error Grid can be seen in Figure 14. Figure 14: Clarke Error Grid •RMSE To have more measurements apart from the Clarke image and the number of points in each zone, we calculate the RMSE i.e root mean square 34 error, following the formula in Figure 15. Due to the RMSE is calculated over glucose values that usually range between 40 and 500 ml/dl, a good RMSE should not exceed 30 mg/dl. Figure 15: Root Mean Squared Error formula 5.2. Results In this section we are going to document all the results obtained after testing different techniques to predict glucose values. 5.2.1. First execution with Patient 1 Our first contact with a real prediction was training the Patient 1 from the Hospital Universitario Pr´ıncipe de Asturias. The patient data-set contained 3824 rows of data after pre-processing, enough to split it into a train and test sets to try out a first execution. The first configuration to generate the supervised data with time series (section 4.3.4) was with 30 minutes, i.e, the train data contains all the information of the patient 120 minutes before the time 0, and the target are all the glucose values after 30 minutes. We used the first configuration of the model (Feed forward described in section 4.3) to test a first execution. The results can be seen in Figure 16. In this first prediction over the test set from the Patient 1, most of the points in the Clarke error grid fall in zone A, but some points are in the critical areas. However, the conclusion of this first execution is that, considering this is a simple model and we only trained 70% of the data-set of one patient, the results are promising with this type of supervised data, with the time series 35 Figure 16: Results of the first training with the supervised data-set and with the parameters trained. This execution is documented in the file ’Hello diabetes.pynb’ 5.2.2. Descriptions of the results To study the different results, we use the following dynamic: 1. Create the model adapted to the type of data #Trained with pat ie nt s that contains i n s u l i n values model 30 i nsulin = crear modeloFF ( number columns ) 2. Train the model for each patient and save the model execute (30 , p at 7 i ns uli n , model 30 insulin , True ) execute (30 , p at 8 i ns uli n , model 30 insulin , True ) execute (30 , p at 9 i ns uli n , model 30 insulin , True ) model 30 i nsulin . save ( ’ Models/ model 30 insulin . h5 ’ ) 36 3. Create a new model for each patient and compare the results of the new model with those of the pre-trained model print (” Patient 7 No t ra in in g ”) execute (30 , p at 7 i ns ul in , crear modeloFF (61) , True ) print (” Patient 7 Trained ”) execute (30 , p at 7 i ns ul in , trained modedl 30 insulin , False ) 5.2.3. Train with Feed Forward The next step was to try this basic model with more patients, and study if training a single model with more than one different patient returns better results. Therefore, we needed to automate the process of preparing the patients (fill NaN values, cut the data-set only with the rows with data, drop useless columns...). All these tests and studies are collected in the file ’Model Dense layer (original FF).pynb’. We are using all the patients with data from Hospital Universitario Pr´ıncipe de Asturias and from Ohio’s Hospital. These first detailed results are for prediction of glucose for 30 minutes: 1. Model with insulin and basic values With this procedure we were able to see notable differences. In the first execution with patients containing basic values and insulin (3 patients), we could appreciate improvements: For instance, with our patient tagged as Patient 8, we got the following results: •Model with no training: Zone A: 880 (76.78883071553228%) Zone B: 246 (21.465968586387437%) Zone C: 7 (0.6108202443280977%) Zone D: 13 (1.1343804537521813%) Zone E: 0 (0.0%) RMSE: 32.800755 •Model pre-trained with other patients: 37 Zone A: 925 (80.7155322862129%) Zone B: 198 (17.277486910994764%) Zone C: 0 (0.0%) Zone D: 23 (2.006980802792321%) Zone E: 0 (0.0%) RMSE: 23.619013 Figure 17: New FF model with glucose, basic vales and insulin Figure 18: Pre-trained FF model with glucose, basic vales and insulin As seen in both figures, the points in the figure 17 (no pre-trained model) are more scattered than in the figure 18 with the pre-trained model. We can appreciate that the pre-trained model tends to group the points. Overall, pre-trained models with different patients with insulin and basic values obtain more accurate results. 2. Model with basic values Then, we proved with the same dynamic explained above to train and prepare a model with patients with only basic values (glucose, steps, heart rate and calories). This model was trained with 10 patients, so the expectations were higher. The model had a notable improvement; when comparing all the Clarke 38 images generated in the notebook for 10 patients, data had visible changes and the goal to group the points in the zone A was almost accomplished. Let’s see an example with the patient tagged as Patient 5: Figure 19: New model of glucose and basic values with FF Figure 20: Pre-trained model of glucose and basic values with FF In Figure 19 we can see that, with a new model, there are many scattered points, but with the pre-trained model (figure 20 the distribution of the points is really remarkable. The RMSE reduces its value from 36.3 to 20.8. The conclusion with this model is that the insulin value is not as relevant as the number of patients and data to train. Furthermore, these evidences confirm that it is possible to have good results with models trained with different patients when personal models are not available. 3. Model with glucose and insulin Afterwards, we created a new model for the Ohio’s Hospital patients in which, after pre-processing their data, we only kept the glucose and insulin values. The data-sets from these patients contain much more data than the Spanish patients. After training the model with all the patients, and comparing the efficiency of the model with the method 39 described before, we noticed that, with this data-set of patients, there is no improvements compared with the others. Also, we could appreciate that only a few have personal behaviours, so the results with a general model are almost the same. Furthermore, as in the others models, we figured out that the full-trained model has the tendency to increase the points that fall in zone A (Figure 21 and 22). Example with our patient tagged as Patient 6 from Ohio’s Hospital: Figure 21: New model of glucose and insulin with FF Figure 22: Pre-trained model of glucose and insulin with FF RMSE new model = 19.19 RMSE pre−trained model = 14.13 4. Model with glucose Finally, we created a general model that can be used for any patient, because it just requires glucose values. This model was trained with all the patients data-sets we had access to, except 3 patients that we reserved to test the model. Instead of comparing the results with a new model and the trained model for every patient, we are going to test the behaviour of the model with three patients that were not used to train the model. This means that we were predicting the glucose 40 Figure 29: New model of glucose and basic values with LSTM Figure 30: Pre-trained model of glucose and basic values with LSTM 3. Model with glucose and insulin Overall, the results with this model are better than with the Feed Forward one, both the RMSE value and in the Clarke image. However, it’s important to mention that a patient (patient tagged as Patient 5) of this set had a peculiar conduct of his glucose level that stands out over the others; that’s the reason why using a new model for this patient returns better results than using a pre-trained model. Nonetheless, the results of both models are really similar. Results of patient tagged as Patient 6: With new model: Zone A: 3665 (89.9607265586647%) Zone B: 396 (9.72017673048601%) Zone C: 0 (0.0%) Zone D: 13 (0.31909671084928815%) Zone E: 0 (0.0%) RMSE: 16.55 With pre-trained model: 47 Zone A: 3849 (94.47717231222386%) Zone B: 217 (5.326460481099656%) Zone C: 0 (0.0%) Zone D: 8 (0.19636720667648502%) Zone E: 0 (0.0%) RMSE: 13.29 4. Model with glucose Finally, after training all the patients only with the glucose parameter, the results are a bit better than with the Feed Forward model, but nothing remarkable. Results for patient tagged as Patient 14 (Figure 31): Figure 31: Results of testing Patient 14 with our 30 min LSTM model that works only with glucose values Zone A: 3394 (88.98793917147351%) Zone B: 388 (10.17304667016256%) Zone C: 0 (0.0%) Zone D: 32 (0.8390141583639223%) Zone E: 0 (0.0%) 48 RMSE: 17.001036 The conclusion after comparing these two models is that the Feed Forward model has a particular behaviour and tendency so, at the time of training a particular patient that has a data-set that stands out over the others, the predictions are worse. On the other hand, the LSTM adapts to the type of patient, making it more reliable and precise. After testing and explaining in detail all the different models with a 30 minutes forecasting, we are going to show the results of the glucose prediction for 60, 90 and 120 minutes. In this case, we are presenting only the glucose model, which returns the best results. We are using our patient tagged as Patient 14 to compare results: •Results for the glucose prediction of 60 minutes (Figure 32): Zone A: 2760 (72.47899159663865%) Zone B: 922 (24.212184873949578%) Zone C: 0 (0.0%) Zone D: 126 (3.308823529411765%) Zone E: 0 (0.0%) RMSE: 28.71 49 Figure 32: Results of testing patient 14 with our 60 min LSTM model that works only with glucose values •Results for the glucose prediction of 90 minutes (Figure 33): Zone A: 2245 (59.047869542346135%) Zone B: 1387 (36.48079957916886%) Zone C: 8 (0.21041557075223566%) Zone D: 160 (4.208311415044713%) Zone E: 2 (0.052603892688058915%) RMSE: 38.74 •Results for the glucose prediction of 120 minutes (Figure 34): Zone A: 2081 (54.82086406743941%) Zone B: 1496 (39.409905163329825%) 50 Figure 33: Results of testing patient 14 with our 90 min LSTM model that works only with glucose values Zone C: 6 (0.15806111696522657%) Zone D: 211 (5.558482613277134%) Zone E: 2 (0.052687038988408846%) RMSE: 42.56 Overall, the results compared to the Feed Forward are really similar, but the training time of all this models is much longer. 51 Figure 34: Results of testing patient 14 with our 120 min LSTM model that works only with glucose values 52 5.2.5. Train with NVIDIA Digits Given the fact that all the different configurations and NN returned similar results, we are going to comment one of them without specific details of the configuration. The NN used for this report is AlexNet network with Adam (Adaptive Moment Estimation) solver / RMSprop, training during 50 epochs with a base learning rate of 0.5. Figure 35: Process of training with all the images on Nvidia Digits In first instance, we saw very promising results with around 78% of accuracy. However, when we wnt into further detail, we noticed that the accuracy remained always around the same value during the whole training. To prove the accuracy of the neural net, we tried 2 different predictions from an Hypo class image and a Normal class image. For both images the result was the same, 78% of Normal in prediction. From this predictions we could observe that the neural net had an statistic influence, 78 % of the images are Normal. To prove that the neural net only used statistical criteria for prediction, we decided to train another neural network with more balanced data input, 64% of Normal images and 36% of Hypo images. 53 Figure 36: Process of training with image-data balanced on Nvidia Digits This last result, shown in Figure 36 could confirm our first hypothesis: the NN is not able to find any characteristic to differentiate between the two classes. There is still a lot of work to do until we reach good results. After our work, we can see two clear ways to find a functional model. •Explore other ways to represent the data with images. •Try out different NN, pre-trained models focused on medical data analysis and apply other techniques such as transferred learning. 54 6. Conclusions and Future work 6.1. General conclusions After having carried out the creation of a NN model to predict glucose levels and a website service where we can share our algorithm with patients of diabetes of type 1, we feel satisfied to have developed a first version of a final service that encompasses both a research work of glucose prediction (covering different scopes in this sector) and an intuitive web interface for the user. In the stage of pre-processing, we learned the different behaviours of diabetes patients and we familiarized with their levels of glucose, discovering which parameters were the best for an accurate prediction. We also realized that much of the patients parameters given were not really necessary to obtain good predictions of glucose, so basic values as the glucose, steps and few more parameters easy to measure are enough to get a precise result. Therefore, if the patient has an appropriate system to measure the levels of glucose, he will be able to obtain good predictions. Also, as seen on the results report, one concept we learned with this study is the following quote: ’the glucose is the ’mirror’ of other diabetes parameters, and the variations of each parameter are reflected in the levels of glucose’. Hence, if the patient has a regular conduct related to physical exercise, food..., the patient should obtain an accurate prediction based only on the evolution of its levels of glucose. After testing all the models implemented with Keras, the idea of predicting glucose behaviour with images came up (J. Ignacio Hidalgo’s idea). We were inexperienced in this type of training using the NVIDIA Digits and, although we didn’t obtain good results because it’s a new field that needs further research, we acquired some knowledge about image training and types of representations for the diabetes parameters. Also, we discovered that it is a really good system to return prediction results, because this service has a 55 really intuitive and visual interface. However, as we were more familiar with the Python scripts and we were incapable of obtaining safe and reliable results with NVIDIA Digits, we decided to use the developed models in Python. Another aspect to highlight is that this full project was realized at the distance, because both of us had an Erasmus studentship, and the hole project was developed through video calls from Leiden, Netherlands (Alvaro’s destination) and Mil´an, Italy (Alejandro’s destination). Also we had weekly calls with our tutor J. Ignacio Hidalgo, and we didn’t experience problems and realized that it is possible to work far from each other. Overall, we acquired valuable knowledge related to diverse fields of computer science such as: data from diabetes patients, correlation of data with glucose, types of predictions for glucose forecasting, how to create a website with Django and incorporate the implemented scripts, how to connect a SQL database to save the information, etc. In conclusion, we consider that this final degree project is the result and representation of four years of learning. 6.2. Future work Since the approach of the project is very general and the main objective was to create a fully working online application that provides useful information to patients, we could not get deep on each one of the task involving GlucNet. Obviously, there is a lot of investigation remaining on the structure of the neural nets. With the existing technologies, different libraries and types of NN it is not possible to try out every options. Anyways, this is the work that needs to be done now on, with the support of the current website. Also, other techniques in the glucose prediction field can be studied in order to give them support on GlucNet. In the future, the idea is to apply different forecasting and ensembles techniques such as KNN, random forest, gradient boosting... and compute more metrics to have a better evaluation of the results. Furthermore, the training and classification of wavelets images is a field which needs time to be studied to accomplish reasonable results. Also, in the future, the idea is to add the results of NVIDIA Digits to the website 56 10. Bibliography •Tensor-flow user guide •Keras user guide (https://keras.io/guides/) •Nvidia Digits user guide •Django user guide •https://ruder.io/optimizing-gradient-descent/index.html •https://diatribe.org/understanding-average-glucose-standard-deviationcv-and-blood-sugar-variability •https://towardsdatascience.com/the-mostly-complete-chart-of-neural-networksexplained-3fb6f2367464 •Stackoverflow •Multiple other sources References [1] J. I. Hidalgo, J. M. Colmenar, G. Kronberger, S. M. Winkler, O. Garnica, J. Lanchares, Data based prediction of blood glucose concentrations using evolutionary methods, J. Medical Systems 41 (2017) 142. [2] C. P´erez-Gand´ıa, A. Facchinetti, G. Sparacino, C. Cobelli, E. G´omez, M. Rigla, A. de Leiva, M. Hernando, Artificial neural network algorithm for online glucose prediction from continuous glucose monitoring, Diabetes technology & therapeutics 12 (2010) 81–88. [3] V. Tresp, T. Briegel, J. Moody, Neural-network models for the blood glucose metabolism of a diabetic, IEEE Transactions on Neural networks 10 (1999) 1204–1213. [4] F. Allam, Z. Nossai, H. Gomma, I. Ibrahim, M. Abdelsalam, A recurrent neural network approach for predicting glucose concentration in type1 diabetic patients, in: Engineering Applications of Neural Networks, Springer, 2011, pp. 254–259. 63 [5] Q. Sun, M. V. Jankovic, L. Bally, S. G. Mougiakakou, Predicting blood glucose with an lstm and bi-lstm based deep neural network, in: 2018 14th Symposium on Neural Networks and Applications (NEUREL), IEEE, 2018, pp. 1–5. [6] E. M. Aiello, G. Lisanti, L. Magni, M. Musci, C. Toffanin, Therapydriven deep glucose forecasting, Engineering Applications of Artificial Intelligence 87 (2020) 103255. [7] T. El Idriss, A. Idri, I. Abnane, Z. Bakkoury, Predicting blood glucose using an lstm neural network, in: 2019 Federated Conference on Computer Science and Information Systems (FedCSIS), IEEE, 2019, pp. 35–41. [8] C. Meijner, S. Persson, Blood Glucose Prediction for Type 1 Diabetes using Machine Learning Long Short-term Memory based models for blood glucose prediction, Master’s thesis, 2017. [9] J. Martinsson, A. Schliep, B. Eliasson, C. Meijner, S. Persson, O. Mogren, Automatic blood glucose prediction with confidence using recurrent neural networks, in: 3rd International Workshop on Knowledge Discovery in Healthcare Data, KDH@ IJCAI-ECAI 2018, 13 July 2018, 2018, pp. 64–68. [10] S. Mirshekarian, R. Bunescu, C. Marling, F. Schwartz, Using lstms to learn physiological models of blood glucose behavior, in: 2017 39th Annual International Conference of the IEEE Engineering in Medicine and Biology Society (EMBC), IEEE, 2017, pp. 2887–2891. [11] S. Mirshekarian, H. Shen, R. Bunescu, C. Marling, Lstms and neural attention models for blood glucose prediction: Comparative experiments on real and synthetic data, in: 2019 41st Annual International Conference of the IEEE Engineering in Medicine and Biology Society (EMBC), IEEE, 2019, pp. 706–712. [12] M. Mayo, L. Chepulis, R. G. Paul, Glycemic-aware metrics and oversampling techniques for predicting blood glucose levels using machine learning, PloS one 14 (2019). 64 [13] K. Li, J. Daniels, C. Liu, P. Herrero, P. Georgiou, Convolutional recurrent neural networks for glucose prediction, IEEE journal of biomedical and health informatics 24 (2019) 603–613. [14] A. Bertachi, L. Biagi, I. Contreras, N. Luo, J. Veh´ı, Prediction of blood glucose levels and nocturnal hypoglycemia using physiological models and artificial neural networks., in: KHD@ IJCAI, 2018, pp. 85–90. [15] K. S. Eljil, G. Qadah, M. Pasquier, Predicting hypoglycemia in diabetic patients using time-sensitive artificial neural networks, International Journal of Healthcare Information Systems and Informatics (IJHISI) 11 (2016) 70–88. [16] X. Mo, Y. Wang, X. Wu, Hypoglycemia prediction using extreme learning machine (elm) and regularized elm, in: 2013 25th Chinese Control and Decision Conference (CCDC), IEEE, 2013, pp. 4405–4409. [17] P. P. San, S. H. Ling, H. Nguyen, et al., Evolvable rough-block-based neural network and its biomedical application to hypoglycemia detection system, IEEE transactions on cybernetics 44 (2013) 1338–1349. 65