Abstract Introduction Type 2 diabetes mellitus (T2DM) is associated with accelerated development of atherosclerosis and a reduced life expectancy. Using machine learning (ML) to identify novel characteristics from electronic medical records (EMRs) associated with prognosis may increase prognostic precision and find new targets for investigation and treatment. Aim We used a novel ML approach to investigate the use of EMRs to predict all-cause mortality in two ethnically and geographically different populations; one from the West of Scotland (WoS) and the other from Hong Kong. Methods We obtained EMRs including demographics, prior comorbidities, laboratory measurements, medications, and mortality. Multivariable Cox regression and time-dependent random forest model were used to identify predictors of all-cause mortality in patients with T2DM. Subsequently, we applied a state-of-the-art ML interpretability method, to gain further insight into the key predictors. Results In WoS, 46,031 individuals received a new diagnosis of T2DM between 2009 and 2019. Their median age was 66 (IQR: 56 to 75) years. Within 10 years, 11,727 (25%) deaths were recorded. In Hong Kong, 273,876 patients with a first-attendance with T2DM at public hospitals or clinics were included, with follow-up until December 2019. The median age of the patients was 64 (IQR: 57 to 72) years. Within 10 years, 91,155 (33%) deaths were recorded. For both cohorts, the strongest predictor for all-cause mortality was prescription of loop diuretics (Figure 1). For the WoS, other important predictors were greater age, lower serum albumin, elevated alanine transaminase (ALT), increased alkaline phosphatase (ALP), and lower estimated glomerular function rate (eGFR) (c-index: 0.83; Brier score: 0.07). For Hong Kong, predictive variables were remarkably similar and included greater age, lower eGFR, lower haemoglobin and lymphocytes, lower serum albumin, and elevated ALP (c-index: 0.85; Brier score: 0.06). Multivariable Cox regression adjusting for age and sex showed a higher mortality amongst those prescribed loop diuretics compared to those who were not (WoS: hazard ratio: 1.549, 95% CI: 1.521 to 1.575; Hong Kong: hazard ratio: 1.745 (95% CI: 1.721 to 1.769). Only a minority of patients prescribed loop diuretics had a diagnosis of heart failure, end-stage renal disease or resistant hypertension. Conclusion Amongst patients with recent-onset T2DM, prescription of loop diuretics was the most important predictor of all-cause mortality in both WoS and Hong Kong. Prescription of loop diuretics might be a pharmacological marker of congestion and undiagnosed heart failure or loop diuretics might have deleterious effects on the outcome of patients with T2DM.Fig 1:Predictors of all-cause Mortality