AKU’s Machine Learning Maps Hidden Diabetes Risk Groups

Four glowing clusters of data points in different colours floating above a softly lit hospital corridor
AI-generated illustration

Every hospital discharge leaves behind a trail of diagnosis codes. Most of the time those codes are used for billing and then forgotten. A team at Aga Khan University (AKU) in Karachi asked a different question: if you hand fourteen years of those codes to an unsupervised machine learning algorithm, will it find patterns that doctors and hospital planners should care about? The answer, published in BMJ Open, is yes. Working with records from 78,271 adults with diabetes, the algorithm sorted patients into four groups without being told what to look for, and one of those groups turned out to have an in-hospital death rate of 18.1%, more than eight times that of the lowest-risk group.

For anyone tracking how artificial intelligence is moving into health care, the study is a useful counterpoint to the headline-grabbing world of large language models. It shows what plain, structured data that almost every hospital already holds can reveal.

The study at a glance

  • Title: Identification of comorbidity-based clusters and mortality risk in hospitalised patients with diabetes mellitus in Karachi, Pakistan: a machine learning analysis
  • Journal: BMJ Open, volume 16, issue 8, article e106407 (peer reviewed, open access under a CC BY-NC 4.0 licence)
  • Published: 31 August 2026
  • DOI: 10.1136/bmjopen-2025-106407
  • AKU team: Namra Aziz (Aga Khan University Hospital, first and corresponding author), Zarmeen Nasim, Zainab Samad, Hooria Imran, Rabiya Owais, Asma Ahmed and Aysha Almas, according to the AKU eCommons record
  • Partners: Tariq Mahmood of the Institute of Business Administration (IBA) Karachi and Gerald S. Bloomfield of Duke University
  • Funding: the Fogarty International Center of the US National Institutes of Health, award D43TW011625
  • Design: retrospective cross-sectional analysis of routinely collected hospital data
  • Sample and setting: 78,271 adults (18 and older) with diabetes admitted to Aga Khan University Hospital, Karachi, between 2008 and 2021
  • Ethics: exempted from full review by the AKU Ethics Review Committee because only anonymised retrospective data were used

IBA Karachi reports that the analysis began as Namra Aziz’s MS thesis in data science, co-supervised by Dr Aysha Almas of AKU Hospital, and that Aziz was the first MS scholar to receive the Fogarty Fellowship at AKU Hospital.

The problem and why it matters

Diabetes is one of the fastest growing chronic diseases on the planet. The World Health Organization estimates that the number of people living with the condition rose from 200 million in 1990 to 830 million in 2022, with prevalence climbing faster in low and middle income countries than in wealthy ones. WHO attributes about 2.0 million deaths in 2023 directly to diabetes, plus another 390,000 kidney disease deaths caused by it, and notes that treatment coverage is lowest in exactly the countries where cases are growing fastest.

Inside hospitals, the challenge is rarely diabetes on its own. The AKU authors point out that people with diabetes commonly carry several other long-term conditions at once, such as heart disease, high blood pressure and kidney disease, and that this multimorbidity drives hospital stays, disability and early death. Real patients arrive as bundles of interacting conditions, and a hospital that cannot see those bundles struggles to decide who needs closer monitoring.

In Pakistan, where the diabetes burden is rising steeply, hospital evidence on which combinations are most dangerous has been thin. The authors believe this is the country’s first machine learning clustering study of hospitalised patients with diabetes.

How the researchers did it, in plain language

The team pulled diagnosis codes (in the international ICD-9 and ICD-10 systems) from the hospital’s information management system for every adult with diabetes admitted over the 14-year window, counting only each patient’s first admission. Patients who were transferred out or left against medical advice were excluded. Codes covering 223 coexisting conditions were turned into simple yes or no flags for each patient.

Similar diagnoses were then merged by organ system, two physicians scored each variable for clinical relevance (33 low scorers were dropped), and 15 variables present in fewer than 1% of patients were removed. That left 47 diagnosis variables. Age and sex were deliberately kept out of the clustering so the groups would reflect disease patterns alone.

The core engine was K-Modes, a cousin of the better-known K-Means algorithm that is built for categorical data. Instead of measuring distance on a continuous scale, it counts how many yes or no flags differ between two patients (the Hamming distance) and assigns each patient to the group whose typical profile is closest. The team also tested K-Means, DBSCAN, spectral and hierarchical clustering and Gaussian mixture models, tuned with grid search and Bayesian optimisation; methods built for continuous numbers performed poorly on this all-categorical data.

The researchers tried three to nine clusters. The silhouette score, a measure of group separation, peaked at nine (0.248) but rose and fell unevenly, so the authors did not treat nine as a stable optimum. Four clusters scored 0.206, and a senior physician confirmed four was the smallest number at which every group had a clearly distinct pattern.

To check the human labels, the team used two text-mining techniques, Latent Dirichlet Allocation and TF-IDF, to surface each cluster’s most characteristic diagnoses; the machine labels matched the clinicians’ closely. Finally, logistic regression measured how strongly membership in each cluster was linked to dying in hospital, first on its own and then adjusted for age, sex and type of health coverage.

Key findings, by the numbers

According to the paper, 42.8% of patients were 60 or over, 39.4% were 41 to 60 and 17.9% were 18 to 40. Type 2 diabetes dominated (77,199 patients), with 315 cases of type 1 and 757 of gestational diabetes. Strikingly, 93.2% of patients had diabetes recorded as a secondary diagnosis, meaning most were admitted for something else. Most (83.5%) paid out of pocket.

The algorithm found four groups:

  • Cardio, tumour and tobacco (CTT): the lowest-burden group, with tumours in 10.4% and no hypertension. Its patients skewed younger, and 59.2% were women.
  • Renal complication cluster (RCC): acute kidney injury in 97%, diabetic kidney disease in 82.5%, hypertension in 88.7%, pneumonia in 52.3% and sepsis in 34.9%.
  • Cardiovascular cluster (CVC): coronary artery disease and hypertension in every patient, heart attack in 32.1%, and the highest tobacco use (20.4%). It was mostly older and 65.9% male.
  • Hypertension, stroke and kidney (HSK): hypertension in all patients, with the highest counts of poorly controlled diabetes (12.7%) and tumours (12.8%).

The difference in outcomes was stark. In-hospital mortality reached 18.1% in RCC (682 deaths), compared with 4.4% in CVC (543), 4% in HSK (1,379) and 2.2% in CTT (603). Against the CTT group, the unadjusted odds of dying in hospital were 9.9 times higher in RCC (95% CI 8.9 to 11.2), 2.1 times higher in CVC and 1.9 times higher in HSK. After adjusting for age, sex and health coverage, the gap narrowed but held: an odds ratio of 6.16 for RCC (95% CI 5.4 to 6.9) and 1.27 for both CVC and HSK, all statistically significant.

The authors link the kidney group’s risk to progressive organ damage from diabetic kidney disease and high blood pressure, worsened in parts of the region by delayed kidney replacement therapy and limited dialysis access.

What is new here

Clustering people with diabetes is not new in itself. Well-known studies have split patients into subtypes using lab values such as body mass index, age at diagnosis and blood sugar control. The AKU study takes a different angle in three ways.

  • Breadth of conditions: rather than a handful of metabolic markers, it started from 223 coexisting conditions, capturing the full multimorbidity picture of hospital patients.
  • Fit-for-purpose algorithm: by matching K-Modes to purely categorical data, the team avoided forcing yes or no codes into methods built for continuous numbers, and produced firm, one-group-per-patient assignments that the authors argue are easier to act on clinically than probabilistic approaches.
  • Machine-checked labels: using topic modelling (LDA and TF-IDF) to confirm what clinicians called each group is a practical guard against wishful interpretation, and an idea other health data teams could borrow.

The authors note that a Singapore study of 71,125 patients, using a probabilistic method, found broadly similar groups, which they read as support for K-Modes as an efficient alternative.

Limitations the authors flag

The paper is candid about what it cannot show:

  • As a retrospective, cross-sectional study, it cannot establish cause and effect or show how patients move between risk groups over time.
  • All data came from one tertiary hospital, which likely over-represents complex cases and limits how far the findings generalise across Pakistan.
  • Important factors such as how long patients had diabetes, medication adherence and lifestyle were not available for adjustment.
  • Choosing four clusters over the higher-scoring nine was not prespecified, so investigator bias cannot be fully excluded.
  • The clusters were validated only internally, and other methods could group patients differently.

What it means for health systems, policy and industry

The most practical idea sits in the paper’s future directions. The authors suggest that, once validated, these clusters could be built into electronic health records so that patients are categorised in real time and flagged with targeted alerts. That is a concrete clinical decision support use case, and it rests on data hospitals already code for every discharge.

For hospital leaders and health IT teams:

  • Existing data is an asset. Coded diagnoses, often treated as an administrative by-product, carried enough signal here to separate a group with an 18.1% in-hospital death rate from one at 2.2%.
  • Simple, explainable models matter. Clusters with labels clinicians can read may be easier to govern and trust than black-box predictors.
  • Validation comes before deployment. The authors call for multi-hospital studies that include rural and semi-urban populations, added social and behavioural data, external validation and comparisons with other models.
  • Cross-sector partnerships pay off. A medical college, a business school, a US university and an NIH training grant together produced the work.

For policymakers, the finding that kidney-related complications cluster with the highest risk adds weight to the case for investing in kidney care capacity. These are research findings about populations, not guidance for individual patients, who should rely on their own clinicians.

Conclusion

The AKU study does not introduce a flashy new model. Its value is in showing, at a scale of more than 78,000 patients, that a well-chosen unsupervised algorithm can turn routine hospital codes into distinct, clinically readable risk groups, and that one of those groups, defined by kidney complications, faces a far higher chance of dying in hospital. With external validation and longitudinal follow-up, the approach could become the backbone of early-warning tools in hospitals that cannot afford elaborate data infrastructure. For a region where diabetes is rising fastest, that is the kind of pragmatic innovation that can travel.

Sources