**Background:** Acid-base and electrolyte imbalances are common in critically ill patients and can lead to serious complications including cardiac arrhythmias and death. Early detection of these imbalances could enable timely intervention and improve patient outcomes. While machine learning has been extensively applied to predict mortality, sepsis, and acute kidney injury in ICU settings, prediction of acid-base disturbances and potassium imbalances remains underexplored. This study aimed to develop and compare machine learning models for predicting nine clinical conditions related to acid-base and potassium balance in intensive care patients.
**Methods:** The study used de-identified electronic health record data from Songklanagarind Hospital in Thailand, including patients admitted from August 2019 to April 2022 who spent at least 24 hours in the medical intensive care unit (MICU). The dataset comprised 1,089 patients with 1,137 admissions (mean age 63.8 years, 55.3% male, mean ICU stay 7.0 days). A total of 87 clinical variables were used as predictors, including vital signs, general patient appearance, and laboratory measurements (blood chemistry, hematology, microbiology, and arterial blood gases). Nine clinical conditions were predicted: mortality, hypocapnia (pCO2 < 35 mmHg), hypercapnia (pCO2 > 45 mmHg), hypokalemia (K+ < 3.5 mmol/L), hyperkalemia (K+ > 5.5 mmol/L), metabolic acidosis (pH < 7.35, cHCO3- < 22 mmol/L), metabolic alkalosis (pH > 7.45, cHCO3- > 26 mmol/L), respiratory acidosis (pH < 7.35, pCO2 > 45 mmHg), and respiratory alkalosis (pH > 7.45, pCO2 < 35 mmHg). Data were formatted into time series with 15-minute intervals using forward-fill imputation. Four machine learning algorithms were evaluated: K Nearest Neighbours (KNN), Support Vector Machine (SVM), Random Forest (RF), and Gradient Boosting (GB). A 12-hour observation window was used, and predictions were made at 1, 2, 4, and 8 hours before clinical onset. Performance was assessed using precision, sensitivity, specificity, F1 score, area under the receiver operating characteristic curve (AUROC), and area under the precision-recall curve (AUPRC).
**Key Results:** Gradient Boosting outperformed other algorithms in 7 of 9 clinical conditions for 1-hour prediction. For mortality, GB achieved AUROC = 0.9822 and AUPRC = 0.8557. For hypokalemia, GB achieved AUROC = 0.9191 and AUPRC = 0.9455. For hyperkalemia, GB achieved AUROC = 0.9565 and AUPRC = 0.6497. For acid-base disorders, AUROCs ranged from 0.7685 (respiratory alkalosis) to 0.8682 (metabolic acidosis). Random Forest slightly outperformed GB for hypercapnia (AUROC = 0.8228 vs 0.8255) and metabolic acidosis (AUROC = 0.8682 vs 0.8699). KNN performed poorly across all conditions. When extending the prediction window from 1 to 8 hours, mortality, hypokalemia, and metabolic alkalosis showed relatively robust performance (AUROC decreases less than 0.05), while larger decreases were observed for hypercapnia, hyperkalemia, respiratory acidosis, and respiratory alkalosis. Feature importance analysis revealed that patient consciousness was most important for mortality prediction; pCO2 and TCO2 for hypocapnia and hypercapnia; potassium measurements for hypokalemia and hyperkalemia; and acid-base balance indicators (SBE, ABE, pCO2, TCO2, cHCO3, K+, Na+) for acid-base disorders.
**Clinical Implications:** The study demonstrates that machine learning models, particularly Gradient Boosting, can predict acid-base and potassium imbalances in ICU patients with clinically meaningful accuracy using routinely collected clinical data. The ability to predict these conditions 1-8 hours in advance could enable earlier clinical intervention, potentially reducing complications and improving patient outcomes. The use of SHAP values for model interpretability addresses the critical need for transparency in clinical decision support systems. However, the study was conducted at a single institution with a relatively small dataset (1,089 patients), and results may not be generalizable to other settings. Future work should examine generalizability across different datasets (e.g., MIMIC, eICU), incorporate continuous bedside monitoring data, and explore the impact of medications and physician diagnoses on prediction performance.