A clinically weighted loss function for risk-sensitive blood glucose forecasting
Blood glucose forecasting models have the potential to improve glycemic control and reduce the burden of diabetes management. However, most prior work has focused on optimizing statistical accuracy, which does not necessarily align with clinical safety and efficacy. This study introduces a clinically weighted root mean squared error (CW-RMSE) loss function that incorporates clinical risk into model optimization by weighting prediction errors according to continuous glucose error grid analysis (CG-EGA) classification and glycemic range to reduce clinically harmful errors. WinFormer, an Informer-based prediction model employing windowed attention, was trained using the REPLACE-BG dataset and either root mean squared error (RMSE) or CW-RMSE loss functions to predict blood glucose values over a 120-min prediction horizon. Compared to RMSE loss, CW-RMSE loss produced significant improvements in CG-EGA classification in hypoglycemia (accurate predictions: 83.2% to 88.0%; erroneous predictions: 13.2% to 8.1%) while maintaining performance for predictions of values in euglycemic (accurate predictions: 92.6% to 92.4%; erroneous predictions: 2.7% to 2.4%) and hyperglycemic ranges (accurate predictions: 91.2% to 90.6%; erroneous predictions: 4.1% to 4.1%). In comparison to RMSE loss, CW-RMSE loss also led to significant improvements in RMSE and mean absolute error (MAE) in hypoglycemia (RMSE: 39.8 mg/dL to 29.8 mg/dL; MAE: 26.6 mg/dL to 16.4 mg/dL), but worse RMSE and MAE in the euglycemia range (RMSE: 31.8 mg/dL to 33.8 mg/dL; MAE: 23.1 mg/dL to 25.1 mg/dL) and the hyperglycemia range (RMSE: 44.9 mg/dL to 52.3 mg/dL; MAE: 30.0 mg/dL to 34.8 mg/dL). These findings demonstrate that cost-sensitive learning can effectively guide blood glucose forecasting models toward more clinically meaningful and risk-aware optimization.

- Lucier J, Mathias PM. Type 1 diabetes. In: StatPearls. Treasure Island, FL: StatPearls Publishing; 2024. Last accessed on February 11, 2026. https://www.ncbi.nlm.nih.gov/books/NBK507713/
- Battelino T, Danne T, Bergenstal RM, et al. Clinical targets for continuous glucose monitoring data interpretation: recommendations from the international consensus on time in range. Diabetes Care. 2019;42(8):1593-1603. doi: 10.2337/dci19-0028
- Hankosky ER, Schapiro D, Gunn KB, Lubelczyk EB, Mitroi J, Nelson DR. Gaps remain for achieving HbA1c targets for people with type 1 or type 2 diabetes using insulin: results from NHANES 2009–2020. Diabetes Ther. 2023;14(6):967- 975. doi: 10.1007/s13300-023-01399-0
- Duinkerken E, Snoek FJ, de Wit M. The cognitive and psychological effects of living with type 1 diabetes: a narrative review. Diabet Med. 2020;37(4):555-563. doi: 10.1111/dme.14216
- Bollepalli S, Smith LB, Vasquez A, Rodriguez H, Vehik K. Addressing the burdens of type 1 diabetes in youth. Clin Pract. 2012;9(4):409-424. doi: 10.2217/cpr.12.33
- Joensen LE, Almdal TP, Willaing I. Associations between patient characteristics, social relations, diabetes management, quality of life, glycaemic control and emotional burden in type 1 diabetes. Prim Care Diabetes. 2016;10(1):41-50. doi: 10.1016/j.pcd.2015.06.007
- Lin R, Brown F, James S, Jones J, Ekinci E. Continuous glucose monitoring: a review of the evidence in type 1 and type 2 diabetes mellitus. Diabet Med. 2021;38(5):e14528. doi: 10.1111/dme.14528
- DiMeglio LA, Evans-Molina C, Oram RA. Type 1 diabetes. Lancet. 2018;391(10138):2449-2462. doi: 10.1016/S0140-6736(18)31320-5
- Ehrmann DE, Laviola L, Priesterroth LS, Hermanns N, Babion N, Glatzer T. Fear of hypoglycaemia and diabetes distress: expected reduction by glucose prediction. J Diabetes Sci Technol. 2024;18(5):1027-1034. doi: 10.1177/19322968241267886
- Liu K, Li L, Ma Y, et al. Machine learning models for blood glucose level predictions in patients with diabetes mellitus: systematic review and network meta-analysis. JMIR Med Inform. 2023;11(1):e47833. doi: 10.2196/47833
- Langarica S, de la Vega D, Cariman N, et al. Deep learning–based glucose prediction models: a guide for practitioners and a curated dataset for improved diabetes management. IEEE Open J Eng Med Biol. 2024;5(5):467-475. doi: 10.1109/OJEMB.2024.3365290
- Vaswani A, Shazeer N, Parmar N, et al. Attention is all you need. arXiv. Preprint posted June 12, 2017. doi: 10.48550/arXiv.1706.03762
- Zhou H, Zhang S, Peng J, et al. Informer: beyond efficient transformer for long sequence time-series forecasting. AAAI. 2021;35(12):11106-11115. doi: 10.1609/aaai.v35i12.17325
- Zhou H. Informer2020 [software]. GitHub. Published 2020. Last accessed on February 11, 2026. https://github.com/ zhouhaoyi/Informer2020
- Sergazinov R, Armandpour M, Gaynanova I. Gluformer: transformer-based personalized glucose forecasting with uncertainty quantification. In: Proceedings of the ICASSP 2023 - 2023 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP); June 4-10, 2023; Rhodes Island, Greece. IEEE; 2023:1-5. doi: 10.1109/icassp49357.2023.10096419
- Zhu T, Chen T, Kuang L, Zeng J, Li K, Georgiou P. Edge-based temporal fusion transformer for multi-horizon blood glucose prediction. In: Proceedings of the IEEE International Symposium on Circuits and Systems (ISCAS); May 21–25, 2023; Monterey, CA. IEEE; 2023. doi: 10.1109/ISCAS46773.2023.10181448
- Cheng M, Diao X, Cui Y, Liu W, Cheng S. Toward short-term glucose prediction solely based on CGM time series. arXiv. Preprint posted April 18, 2024. doi: 10.48550/arXiv.2404.11924
- Zhu T, Afentakis I, Li K, et al. Multi-Horizon Glucose Prediction Across Populations With Deep Domain Generalization. IEEE J Biomed Health Inform. 2025;29(8):5424-5437. doi: 10.1109/jbhi.2024.3428921
- Xue Y, Guan S, Jia W. BGformer: an improved Informer model to enhance blood glucose prediction. J Biomed Inform. 2024;157(1):104715. doi: 10.1016/j.jbi.2024.104715
- de Bois M, El Yacoubi MA, Ammi M. GLYFE: review and benchmark of personalised glucose predictive models in type 1 diabetes. Med Biol Eng Comput. 2021;60(1):1-17. doi: 10.1007/s11517-021-02437-4
- Clarke W, Cox D, Gonder-Frederick LA, Carter W, Pohl SL. Evaluating clinical accuracy of systems for self-monitoring of blood glucose. Diabetes Care. 1987;10(5):622-628. doi: 10.2337/diacare.10.5.622
- Kovatchev BP, Cox DJ, Gonder-Frederick LA, Clarke WL. Evaluating the accuracy of continuous glucose-monitoring sensors: continuous glucose-error grid analysis illustrated by TheraSense Freestyle Navigator data. Diabetes Care. 2004;27(8):1922-1928. doi: 10.2337/diacare.27.8.1922
- Devi D, Biswa SK, Purkayastha B. A review on solution to class imbalance problem: undersampling approaches. In: Proceedings of the International Conference on Computational Performance Evaluation (ComPE); July 2–4, 2020; Shillong, India. IEEE; 2020. doi: 10.1109/ComPE49325.2020.9200087
- Saripuddin M, Suliman A, Sameon SS, Jorgenson BN. Random undersampling on imbalanced time series data for anomaly detection. In: Proceedings of the 4th International Conference on Machine Learning and Machine Intelligence (MLMI 2021); September 17–19, 2021; Hangzhou, China. ACM; 2021:151-156. doi: 10.1145/3490725.3490748
- Araf I, Idri A, Chairi I. Cost-sensitive learning for imbalanced medical data: a review. Artif Intell Rev. 2024;57(4). doi: 10.1007/s10462-023-10652-8
- Aleppo G, Ruedy KJ, Riddlesworth TD, et al. REPLACE-BG: a randomized trial comparing continuous glucose monitoring with and without routine blood glucose monitoring in adults with well-controlled type 1 diabetes. Diabetes Care. 2017;40(4):538-545. doi: 10.2337/dc16-2482
- Jaeb Center for Health Research. REPLACE-BG public dataset [data set]. 2017. Last accessed on February 11, 2026. https://public.jaeb.org/dataset/546
- Passant J. Informer-based blood glucose prediction: a comparative analysis of attention mechanisms and training methods. Master’S dissertation. Liverpool, UK: University of Liverpool; 2024. Last accessed on May 22, 2026. https://github.com/JosephPassant/Blood-Glucose-Prediction/blob/ /report/passant_ibgp.pdf
- de Bois M. CG-EGA [software]. GitHub. Published 2020. Last accessed on February 11, 2026. https://github.com/dotXem/CG-EGA
- Ahmed B, Ali ME, Masud MM, Nazni M. Recent trends and techniques of blood glucose level prediction for diabetes control. Smart Health. 2024;32:100457. doi: 10.1016/j.smhl.2024.100457
- Katsarou DN, Georga EI, Christou MA, et al. Optimizing hypoglycaemia prediction in type 1 diabetes with ensemble machine learning modeling. BMC Med Inform Decis Mak. 2025;25(1):46. doi: 10.1186/s12911-025-02867-2
- Alshehri OS, Alshehri OM, Samma H. Blood glucose prediction using RNN, LSTM and GRU: a comparative study. In: Proceedings of the IEEE International Conference on Advanced Systems and Emergent Technologies (IC_ASET); April 27–29, 2024; Hammamet, Tunisia. IEEE; 2024. doi: 10.1109/IC_ASET61847.2024.10596176
- Annuzzi G, Arpaia P, Bozzetto L, Criscuolo S, Giugliano S, Pesola M. Assessing the features on blood glucose level prediction in type 1 diabetes patients through explainable artificial intelligence. In: Proceedings of the IEEE International Conference on Metrology for Extended Reality, Artificial Intelligence and Neural Engineering (MetroXRAINE); October 25–27, 2023; Milan, Italy. IEEE; 2023. doi: 10.1109/MetroXRAINE58569.2023.10405831
- Butunoi BP, Stolojescu-Crisan C, Negru V. Short-term glucose prediction in type 1 diabetes. Procedia Comput Sci. 2024;238(10):41-48. doi: 10.1016/j.procs.2024.05.194
- Nordin MSM, Mahmud F. Univariate and multivariate time series blood glucose prediction with LSTM deep learning model. Evol Electr Electron Eng. 2024;5(1):276-285. Last accessed on February 11, 2026. https://publisher.uthm.edu. my/periodicals/index.php/eeee/article/view/15439. doi: 10.30880/eeee.2024.05.01.035
- Rehman NU, Contreras I, Benyeto A, Vehi J. The impact of missing continuous blood glucose samples on machine learning models for predicting postprandial hypoglycaemia: an experimental analysis. Mathematics. 2024;12(10):1567. doi: 10.3390/math12101567
- Mohamed Youssuff AR, Zainulabedin Hasan M, Anand R, Rajasekhara Babu M. Leveraging deep learning models for continuous glucose monitoring and prediction in diabetes management: toward enhanced blood sugar control. J Syst Assur Eng Manag. 2024;15(6):2077-2084. doi: 10.1007/s13198-023-02200-y
- Stawarz K, Katz D, Ayobi A, et al. Co-designing opportunities for human-centred machine learning in supporting type 1 diabetes decision making. Int J Hum Comput Stud. 2023;173:103003. doi: 10.1016/j.ijhcs.2023.103003
- Barth CM, Bernard J, Huang EM. “It’s like a glimpse into the future”: exploring the role of blood glucose prediction technologies for type 1 diabetes self-management. In: Proceedings of the 2024 CHI Conference on Human Factors in Computing Systems (CHI ’24); May 11–16, 2024; Honolulu, HI. ACM; 2024:1-21. doi: 10.1145/3613904.3642234
