Using machine learning and explainable AI to explore dietary factors associated with type 2 diabetes: a cross-sectional study from the UK NDNS
Introduction Limited studies have applied machine learning and explainable artificial intelligence (XAI) methods to identify dietary factors associated with type 2 diabetes mellitus (T2DM) but none in UK populations. We conducted an exploratory cross-sectional analysis of the UK National Diet and Nutrition Survey (NDNS) data to explore dietary factors alongside anthropometric and demographic measures. Methods Data from NDNS years 1–11 (2008–2019) were analysed for 4460 adults (251 with self-reported T2DM); 24 dietary variables, including total energy intake, age, sex, ethnicity, body mass index and waist circumference were included in the model. K-nearest neighbour (KNN), decision tree (DT), random forest (RF) and XGBoost models were trained on dietary, anthropometric and demographic variables. Performance was reported per class with 95% CIs. Feature importance and model interpretability were assessed using permutation feature importance, SHAP and LIME. Results RF (ROC-AUC 0.77, 95% CI 0.71 to 0.83; diabetic-class recall 0.24, 95% CI 0.12 to 0.36) and XGBoost (ROC-AUC 0.77, 95% CI 0.70 to 0.83; diabetic-class recall 0.34, 95% CI 0.21 to 0.48) achieved comparable performance, both outperforming KNN and DT. Age, waist circumference and BMI were the variables most strongly associated with T2DM classification. Among dietary variables, dietary sugars (free and total) and refined starchy carbohydrates (pasta, rice and other cereals) were most consistently linked to T2DM prevalence. However, SHAP indicated that higher sugar intake was associated with classification towards the non-diabetic class, consistent with reverse causation typical in cross-sectional studies. Most other food groups made small, directionally inconsistent contributions. Conclusion Using machine learning (RF and XGBoost) with explainable AI, this study examined the dietary factors most associated with T2DM classification in NDNS. The cross-sectional design, self-reported T2DM status and predominantly white sample (93%) limit causal inference and generalisability. These dietary associations are therefore hypothesis-generating. Future studies should examine these dietary factors prospectively in larger, more ethnically diverse and externally validated cohorts.
Authors
- Grace Farhat (ORCID: https://orcid.org/0000-0002-7134-7445)
- Shokooh Khandan (ORCID: https://orcid.org/0000-0001-7951-2890)
- Matthew Allward
Institutions
- Manchester Metropolitan University (GB)
Publication Details
- Journal
- BMJ Nutrition Prevention & Health
- Published
- 2026-09-04
- DOI
- https://doi.org/10.1136/bmjnph-2026-001522
- Primary Topic
- Nutritional Studies and Diet
- Type
- article
- Field-Weighted Citation Impact
- 0.00
Funders
- University College London
- Public Health England
- Medical Research Council