University of Nottingham

Scalable Polypharmacy Profiling in Primary Care Records

Data Science

November 23, 2026

This project developed a scalable and interpretable workflow for studying polypharmacy in adults prescribed antidepressants in UK primary care. It turns longitudinal prescribing records into patient-level medicine-count profiles, then uses machine learning and clustering to identify clinically readable patterns.

Polypharmacy is often measured using medicine-count thresholds but counts alone do not explain why patients reach similar prescribing complexity. People with the same number of prescribed medicines may have very different recorded clinical condition profiles. 

The antidepressant-treated cohort needed careful interpretation because antidepressant prescribing does not always equal a coded diagnosis of depression. Medicines may reflect depression, anxiety, pain, sleep disturbance or other clinical contexts. 

The analysis also had to scale: the cohort contained 421,578 adults and 1,811,727 processed prescription-period records, making direct full-cohort density-based clustering impractical. 

Solution

Prescription intervals were processed over the 2019 observation period to derive each patient's maximum concurrent medicine count. This captured peak active prescribing rather than simply counting all prescriptions issued across the year. 

Coded clinical conditions were represented as sparse binary features and analysed across age and sex strata. Logistic regression models supported category classification, while SHAP (Shapley Additive Explanations) values provided condition-level interpretation. 

For patient profiling, the HDBSCAN clustering algorithm was fitted on a 50,000-patient sample and then extended to the wider cohort using approximate prediction in batches. Joblib parallelisation distributed batch prediction across CPU cores.

The supervised models achieved ROC-AUC values of 0.750-0.800 and accuracy of 0.690-0.820. Lower medicine-count groups were identified more reliably than higher groups, suggesting that high polypharmacy reflects more heterogeneous combinations of recorded conditions. 

The all-adult clustering retained 11 clusters representing at least 1% of the population. Profiles showed a medicine-count gradient, from median counts of 3-4 medicines in narrower profiles to 8-10 or more medicines in broader multimorbidity profiles.  

Tech stack

Python, pandas, NumPy, scikit-learn, SHAP, HDBSCAN, Joblib, Matplotlib, Seaborn, Jupyter Notebook, CPRD Gold

Key Features

  • Maximum concurrent medicine count
  • Interpretable machine learning
  • Scalable clustering
  • Readable outputs

Links

CPRD Gold: https://www.cprd.com/primary-care-data-public-health-research

IEEE Big Data 2026: https://bigdataieee.org/BigData2026/

Comments

No comments yet — be the first to comment.

Never shown publicly.