# Development and evaluation of machine learning algorithms for the prediction of opioid-related deaths among UK patients with non-cancer pain

**Authors:** Jose Benitez-Aurioles, Carlos Raul Ramirez Medina, David Jenkins, Niels Peek, Meghna Jani

PMC · DOI: 10.1371/journal.pdig.0001190 · 2026-01-27

## TL;DR

Researchers developed and validated machine learning models to predict opioid-related deaths in UK patients with non-cancer pain, using real-world data to help improve safer prescribing.

## Contribution

First nationally representative models for predicting opioid-related mortality in non-cancer pain patients, accounting for competing risks and censoring.

## Key findings

- Three models (regression, random forest, neural network) showed good discrimination with C-statistics above 81% in both internal and external validation.
- Predictors like prior substance abuse, lung/liver comorbidities, and co-prescription of gabapentinoids were associated with higher opioid-related mortality risk.
- The models were validated using a separate external cohort, demonstrating robustness and generalizability.

## Abstract

The global rise in prescription opioid use has contributed to an opioid epidemic, associated harms, and unintentional deaths in several western countries. Opioids however continue to be regularly prescribed for acute pain and in the chronic pain context due to limited treatment options. Currently there are no accurate tools that help predict which patients prescribed opioids may be at risk of death, which depends on the cultural context and varies across countries. Existing models do not account for statistical considerations such as censoring and competing risks. Using nationally representative data from the United Kingdom from 1,026,139 patients newly prescribed an opioid, we developed three competing risk time-to-event models: a regression model, a random forest, and a deep neural network to predict opioid-related deaths using UK primary care records. The models were externally validated in an external cohort of 337,015 patients. The models exhibited good discrimination and positive predictive value during internal validation (C-statistic for the regression model, random forest, and neural network: 84.3%, 84.4% and 82.1% respectively), and external validation (C-statistic for the regression model, random forest, and neural network: 81.8%, 81.5% and 81.5% respectively). Prior substance abuse, lung and liver comorbidities, morphine, fentanyl, or oxycodone at initiation and co-prescription of gabapentinoids were some of candidate predictors associated with a higher risk of opioid-related mortality within the models. These results demonstrate how routinely collected data from a nationally representative dataset may be used to develop and validate opioids risk algorithms to better help clinicians and patients predict risk to this serious adverse outcome.

The rising use of prescription opioids has led to serious health concerns, including a growing number of preventable deaths. Yet, opioids remain a common treatment for pain, leaving doctors and patients with a difficult balance between benefits and risks. There are no accurate tools to identify which patients prescribed opioids for non-cancer pain may face a higher risk of dying from them. Using electronic health records from over one million people in the United Kingdom who were newly prescribed an opioid, we created and tested three different prediction models, including different types of machine learning. We were able to accurately define opioid-associated deaths from information presented on death certificates. These models used information such as medical history, other medications taken at the same time, and the type/ dose of opioid prescribed to estimate an individual’s risk of opioid-related death. We found that all three models performed well, both when tested on the original data and when tested on a separate group of patients. We developed and validated risk prediction tools to predict the most serious adverse event to opioids for the first time using nationally representative data. These could help guide safer prescribing decisions and support conversations between patients and healthcare professionals about opioid use.

## Linked entities

- **Chemicals:** morphine (PubChem CID 5288826), fentanyl (PubChem CID 3345), oxycodone (PubChem CID 5284603)
- **Diseases:** substance abuse (MONDO:0002491)

## Full-text entities

- **Diseases:** acute pain (MESH:D059787), death (MESH:D003643), lung and liver comorbidities (MESH:D008107), substance abuse (MESH:D019966), cancer (MESH:D009369), pain (MESH:D010146), chronic pain (MESH:D059350)
- **Chemicals:** morphine (MESH:D009020), oxycodone (MESH:D010098), fentanyl (MESH:D005283), gabapentinoids (-)
- **Species:** Homo sapiens (human, species) [taxon 9606]

## Figures

7 figures with captions in the complete paper: https://tomesphere.com/paper/PMC12843567/full.md

---
Source: https://tomesphere.com/paper/PMC12843567