Predicting pneumonia death in patients with heart failure using explainable machine learning model in a territory-wide electronic health record cohort
Y Qi, Q Ren, A Mastumoto, C Wang, G Chen, S Guo, K YiuAbstract
Background
Pneumonia is a major cause of death among patients with heart failure (HF), and improved risk prediction could enable earlier escalation of care and more proactive clinical management. However, robust prediction tools using routinely collected electronic health record (EHR) data for this HF population remain limited.
Objective
To develop and compare machine learning models to predict pneumonia death in patients with HF using territory-wide EHR data, and to identify key predictors driving model output.
Methods
This population-based machine learning study utilized territory-wide EHR data from the Clinical Data Analysis and Reporting System (CDARS) between 2010 and 2024. We assembled an adult cohort from CDARS and defined the study outcome as pneumonia death during follow-up. Candidate predictors were derived from routinely available clinical data, including demographics, lifestyle factors, comorbidities, medications, and laboratory markers. The dataset was randomly split into a training set and an internal test set at an 80:20 ratio using a fixed random seed (seed = 42). We developed and compared six supervised learning models, including logistic regression, random forest, XGBoost, linear support vector machine (SVM), extra-trees, and k-nearest neighbors (KNN), to predict pneumonia death. Model performance was assessed using the area under the receiver-operating-characteristic curve (AUROC) and the area under the precision–recall curve (PR-AUC). Model interpretability was evaluated using the Shapley Additive Explanation (SHAP) method to identify the key predictors driving model output. We further examined feature–outcome relationships using SHAP dependence analyses to characterise potential nonlinear and interaction effects.
Results
A total of 261,633 patients were included, among whom 51,371 died from pneumonia (19.6%). Among the evaluated models, XGBoost achieved the best overall discrimination, with an AUROC of 0.8770 (95% confidence interval [CI] 0.8729–0.8812) and a PR-AUC of 0.8489 (95% CI 0.8425–0.8552). Based on SHAP interpretation, the leading predictors contributing to model output included age, CRP, glucose, hemoglobin (Hb), HbA1c, and renal function markers (creatinine and eGFR), with additional contributions from cardiovascular comorbidities and medication indicators. SHAP dependence analyses further suggested a nonlinear pattern for glycaemic markers, whereby glucose values within a mid-range contributed minimally to model output, whereas more extreme glucose levels were associated with substantially larger SHAP magnitudes.
Conclusion
In this prediction, XGBoost achieved strong discrimination for predicting pneumonia death and identified clinically coherent risk drivers through SHAP. These findings support the potential utility of explainable machine learning for risk stratification and earlier escalation of care in HF populations.ROC and SHAP analysis