An explainable machine learning approach to predicting carbapenem resistance in Klebsiella pneumoniae with imbalanced data and resistance-ratio validation
Abstract
Carbapenem-resistant Klebsiella pneumoniae (CRKP) is a major global health threat. Predicting resistance from electronic medical records (EMRs) may support infection control and antimicrobial stewardship, but class imbalance can impair detection of resistant isolates. This study developed an interpretable machine-learning framework for predicting carbapenem-resistant versus carbapenem-susceptible K. pneumoniae . We retrospectively analyzed 5,794 records collected from 2014 to 2024, including 999 carbapenem-resistant and 4,795 carbapenem-susceptible isolates. The prediction anchor was culture-specimen collection (T0), and all predictors were restricted to information available at or before T0. Seven algorithms and 18 sampling strategies were evaluated using patient-grouped five-fold cross-validation with fold-specific preprocessing. The selected resampling pipeline was compared with Platt-calibrated XGBoost using sensitivity-targeted, F2-maximizing, and cost-sensitive thresholds. Feature-restriction analyses, multiplicity-adjusted comparisons, ICU subgroup analysis, reconstructed prevalence scenarios, calibration assessment, and same-center temporal validation were also performed. XGBoost and LightGBM showed comparable discrimination after multiplicity adjustment. ENN–BLSMOTE–XGBoost increased sensitivity and reduced the very-major-error rate (VME) at the default threshold, but slightly reduced ranking discrimination and increased false-positive alerts. Sensitivity-targeted threshold optimization of calibrated XGBoost produced an operating point close to that of the resampled model, indicating that much of the sensitivity gain could be achieved without changing the training distribution. After all duration-based predictors were excluded, ENN–BLSMOTE–XGBoost retained an ROC AUC of 0.940 and a PR AUC of 0.833. In the 2025 temporal cohort, the calibrated ENN–BLSMOTE–XGBoost model achieved an ROC AUC of 0.889, a PR AUC of 0.684, a sensitivity of 0.749, and a VME of 0.251; Platt scaling reduced its Brier score from 0.121 to 0.108. SHAP analysis identified ICU admission, vascular system disease, days of indwelling urinary catheterization, days of carbapenem use, and days of endotracheal intubation as the five highest-attribution predictors. A web calculator was developed to provide calibrated probability estimates referenced to the 17.24% resistance prevalence of the development cohort. The proposed model effectively addresses class imbalance in predicting carbapenem resistance in K. pneumoniae and may support early identification of patients at risk of harboring carbapenem-resistant isolates, thereby informing infection control and antimicrobial stewardship.