Predicting unfavorable tuberculosis outcomes using machine learning: a prospective cohort Authors: Taehyung Lee, Inseo Choi, Hoyoun Lee, Hyung Woo Kim, Eung Gu Lee, Yeonhee Park, Sung Soo Jung, Jin Woo Kim, Jee Youn Oh, Heayon Lee, Seung Hoon Kim, Sun-Hyung Kim, Jiwon Lyu, Sun Jung Kwon, Yun-Jeong Jeong, Hyeon-Kyoung Koo, Ju Sang Kim, Jinsoo Min Published: 2026 ABSTRACT AbstractBackgroundTuberculosis (TB) continues to be a primary cause of mortality from a singular infectious agent worldwide, with a significant number of patients still encountering unfavorable outcomes such as treatment failure, relapse, or death. Early identification of high-risk individuals is essential for optimizing clinical management, yet conventional statistical approaches often fail to capture the complex, nonlinear interactions among clinical predictors. Machine learning (ML) presents a promising alternative; however, previous ML-based prognostic studies in TB have been constrained by small sample sizes, retrospective designs, or insufficient external validation.MethodsWe conducted a multicenter prospective cohort study in Korea using two prospective cohort databases (2016–2024). Adults with newly diagnosed drug-susceptible pulmonary tuberculosis were divided into training and external validation sets by institutions. Five machine learning models were created, and optimized decision thresholds to get the highest F2-score. We used the area under the receiver-operating characteristic curve (AUROC) and the area under the precision–recall curve to measure performance. Feature importance was assessed using SHapley Additive exPlanations (SHAP) values and compared with multivariate logistic regression.ResultsAmong 1580 participants, 109 (6.9%) experienced unfavorable outcomes. The XGBoost model demonstrated the best discriminative ability, achieving an AUROC of 0.818, and successfully identifying 73.3% of unfavorable outcomes by assessing the top 20% of patients at highest risk. SHAP analysis identified serum albumin, hemoglobin, lymphocyte count, and age as the most significant predictors. Furthermore, multivariate logistic regression analysis revealed that serum albumin (adjusted odds ratio [aOR], 0.492; 95% confidence interval [CI] 0.325–0.743; p < 0.001) and hemoglobin (aOR, 0.858; 95% CI 0.756–0.973; p = 0.017) were independent protective factors of statistical significance. Conversely, a model that excluded laboratory data exhibited diminished performance, with an AUROC of 0.741.ConclusionsThe successful external validation confirmed the high predictive accuracy and generalizability of the ML models, with XGBoost demonstrating the most promising results in forecasting tuberculosis outcomes. Both ML and statistical analyses identified serum albumin and hemoglobin as primary predictors, whereas the ML model also incorporated the prognostic significance of lymphocyte count. These results show that common signs of nutritional and immune health are important factors in predicting the course of tuberculosis.Supplementary InformationThe online version contains supplementary material available at 10.1186/s41182-026-00969-9.Keywords: Tuberculosis, Machine learning, Treatment outcome, XGBoost, Serum albumin, Nutritional status, Hemoglobin, Lymphocyte count, Prospective cohort Background Tuberculosis (TB) continues to rank among the leading causes of death from a single infectious agent globally. Progress in diagnosis and therapy notwithstanding, a substantial proportion of patients still experience unfavorable outcomes—treatment failure, relapse, or death—with the elderly, the malnourished, and individuals burdened by comorbid conditions being disproportionately affected [1, 2]. Accordingly, there is an urgent clinical need for tools that can stratify risk early in the treatment course and inform management decisions. Complex, nonlinear relationships between a variety of clinical variables are difficult for traditional statistical models, for instance logistic regression, to capture. Flexible modeling techniques that can integrate high-dimensional data and identify subtle prognostic patterns are provided by machine learning (ML) [3]. Nonetheless, the majority of preceding machine learning investigations in tuberculosis prognosis have been limited by inadequate sample sizes, retrospective methodologies, or dependence on static baseline data [4]. Large-scale prospective cohort studies validating ML as a risk prediction tool remain scarce. This study used data from a multicenter prospective cohort study [5] in the Republic of Korea, which has a higher TB burden than other high-income countries [6]. Utilizing this resource, we sought to create and assess ML models to predict adverse outcomes in patients with drug-sensitive pulmonary TB at the initial diagnosis. We also compared ML-derived predictors using SHapley Additive exPlanations (SHAP) values with those found by traditional multivariable logistic regression. The objective of this study was to develop and evaluate machine learning models for predicting unfavorable treatment outcomes and enhancing the identification of high-risk patients. Methods Study design and data source We conducted a multicenter prospective observational cohort study in the Republic of Korea. Two prospective cohorts were integrated. The first, COSMOTB (Cohort Study of Pulmonary Tuberculosis), enrolled participants with pulmonary TB at 21 hospitals with the primary goal of identifying biomarkers predictive of anti-TB treatment outcomes [7]. The second, SAFE-TB (Surveillance of Side Effects during Anti-TB Treatment), enrolled participants with TB at 13 hospitals to assess factors associated with adverse drug reactions during anti-TB treatment [8]. The STROBE checklist was used for reporting. The COSMOTB recruited participants between September 2016 and December 2024, while the SAFE-TB recruited between April 2020 and December 2022. As part of the Public–Private Mix TB Control Project [9], all hospitals used the same procedures for diagnosis, treatment, and follow-up. This made it possible to manage TB cases in a systematic way. Participants were monitored until the evaluation of treatment outcomes at the completion of anti-TB therapy, along with additional surveillance for recurrence; the mean follow-up duration was 215.0 days, with a median of 188.0 days. Study participants The COSMOTB database comprised 2884 adults with pulmonary TB and the SAFE-TB cohort included 502 adults with TB. After merging the datasets, participants were excluded due to changes in their diagnoses, duplicate entries, not having pulmonary TB, or withdrawal of consent. This left 2709 participants with pulmonary TB. A further 1129 patients were excluded based on the following criteria: previous history of TB treatment, multidrug-resistant TB, missing or interrupted treatment outcomes (lost to follow-up), unevaluated outcomes (transferred-out), or dropout due to diagnostic revisions. Patients who were lost to follow-up or transferred-out were excluded from the final analysis instead of being imputed. The final study population comprised 1,580 participants with pulmonary TB (Fig. 1). Study flowchart. This flowchart illustrates the selection process of study participants from the COSMOTB and SAFE-TB cohorts and the dual analytical pipeline. From an initial pool of 2709 patients, 1129 were excluded due to drug resistance, retreatment status, incomplete outcomes, or non-standard regimens, yielding 1580 eligible participants. Patients were divided into a training set and an external validation set based on the institution (Chungbuk National University Hospital). The data were analyzed using two parallel approaches: a machine learning pipeline (left) involving preprocessing, hyperparameter optimization via Bayesian optimization (Optuna), and threshold tuning to maximize the F2-score; and a statistical regression pipeline (right) utilizing univariate screening, multivariate logistic regression, and stepwise variable selection. (HREZ, isoniazid, rifampicin, ethambutol, and pyrazinamide; SHAP, SHapley Additive exPlanations.) Variables and outcome definitions The primary outcome was an unfavorable treatment outcome, defined as treatment failure, death, prolonged treatment (over 1 year), or recurrence, according to the Korean TB guidelines adopted from the World Health Organization. Patients with “cured” or “treatment completed” outcomes were classified as having favorable outcomes. Candidate predictors were selected based on established clinical relevance [1, 4, 10]. Demographic characteristics included age, sex, and body mass index (BMI). Past medical history comprised diabetes, chronic pulmonary disease, chronic kidney disease, and histories of smoking and alcohol use. TB-related symptoms at diagnosis—including cough, sputum, hemoptysis, dyspnea, chest discomfort, night sweats, general weakness, anorexia, weight loss, and fever—were recorded. Laboratory measurements included serum albumin, hemoglobin, complete blood count, creatinine, and sputum smear acid-fast bacilli test results. Chest radiographs were evaluated for cavitary lesions and extent of lung involvement. Potential confounders considered in the regression model included age, sex, body mass index (BMI), comorbidities, and symptom profiles. Continuous variables including age, BMI, serum albumin, hemoglobin, lymphocyte count, and creatinine were treated as continuous in both the ML and regression analyses. For the logistic regression, these were entered as linear terms. An outlier removal step excluded patients with weight below 25 kg, white blood cell count exceeding 70,000 /μL, or hemoglobin below 5 g/dL or above 50 g/dL. Composite categorical variables were engineered, including symptom groupings (respiratory, alarming, constitutional) and extent of lung involvement (bilateral, unilateral, or none). Data collection and measurement A standardized electronic case report form from the cohort database was used to gather data at the first visit. All participating sites used the same instruments for gathering data. Standard operating procedures were followed when performing laboratory measurements at each hospital's clinical laboratory. Physicians at the enrolling institution assessed chest radiographs. Because both cohorts followed standardized protocols, assessment techniques were comparable across sites. A multicenter design with broad enrollment criteria minimized selection bias. Standardized electronic case report forms and procedures were used at all participating sites to reduce information bias. All model development procedures, such as preprocessing, hyperparameter optimization, and threshold tuning, were carried out solely on the training set to avoid overfitting and data leakage. To evaluate generalizability, an independent institutional cohort (Chungbuk National University Hospital) was used for external validation. Multivariate logistic regression was used to adjust for significant univariate predictors to address confounding. To assess potential selection or survivorship bias arising from attrition of patients during the treatment period, baseline characteristics of the 1580 included patients were compared with the 109 drug-susceptible, first-treatment, HREZ-treated patients whose treatment outcome was recorded as lost to follow-up (n = 14) or transferred-out (n = 95). Continuous features were compared using the Mann–Whitney U test and categorical features using the chi-square test, with Fisher’s exact test substituted when any expected cell count was below 5 (Supplemental Table S1). The exact missing rate for each model feature was additionally tabulated and listed in Supplemental Table S2. The sample size was decided by the total enrollment of the COSMOTB and SAFE-TB database during their respective recruitment periods. No formal a priori sample size calculation was performed for the present predictive modeling study. However, the final cohort of 1580 patients with 109 unfavorable outcome events was considered sufficient for developing and validating the ML models given the number of predictors used. Statistical and machine learning analyses Our analytical strategy employed a dual-pipeline approach: a machine learning pipeline for predictive modeling and a statistical pipeline for traditional regression analysis (Fig. 1). Data preprocessing and splitting The cohort was divided into a training set and an external validation set based on institution, with Chungbuk National University Hospital serving as the validation site. Missing values for numerical features were imputed using the median; categorical features were replaced with a constant placeholder ("missing"). Numerical features were standardized for the Logistic Regression and Multi-layer Perception (MLP) models, and categorical features were transformed using one-hot encoding. Machine learning model development We developed five supervised ML models: logistic regression with a least absolute shrinkage and selection operator (lasso) penalty, Extra Trees Classifier, XGBoost, CatBoost, and MLP. Hyperparameter optimization with Optuna framework with the Tree-structured Parzen Estimator (TPE) sampler was carried out over 30 trials, by performing threefold stratified cross-validation on the training set to optimize the Area Under the Receiver-Operating Characteristic curve (AUROC). Supplemental Table S3 lists the full hyperparameter search space and final values. To overcome the class imbalance, no resampling methods (e.g., SMOTE) or class-weighting parameters (e.g., scale_pos_weight) were used; instead, we relied exclusively on post-hoc decision-threshold optimization. Notably, our dataset exhibited a significant class imbalance, as unfavorable outcomes are clinically critical but relatively rare events. In medical predictive modeling with such imbalanced datasets, standard metrics can be misleading. Therefore, to prioritize the early detection of these high-risk patients, we calibrated the classification threshold to maximize the F2-score (beta = 2.0). Utilizing the F2-score is a well-established strategy that intentionally places twice as much weight on recall (sensitivity) as on precision, thereby penalizing false negatives more heavily than false positives [11]. This method reduces the number of missed diagnoses, which is important for taking clinical intervention promptly. Fivefold stratified cross-validation on the training set was used to find the best thresholds. A standard multivariable logistic regression model without penalization was developed using the same training and external validation sets as a traditional statistical benchmark for comparing the machine learning models. Its predictive performance was evaluated using the same discrimination metrics; detailed methodology is available in the Supplemental Method. Statistical regression pipeline Potential predictors were screened using univariate logistic regression (p < 0.1), then included in a multivariate logistic regression model to identify independent predictors while controlling for confounding. Results were expressed as odds ratios and adjusted odds ratios (aORs) with 95% confidence intervals (CIs). A two-sided p value < 0.05 was considered significant. Model evaluation Final models were retrained on the entire training set and evaluated on the independent test set using AUROC, area under precision–recall curve (AUPRC), sensitivity, specificity, precision, negative predictive value (NPV), and F2-score. 95% CIs for AUROC were calculated using DeLong’s method. Precision and recall at the top 5, 10, and 20% of predicted risk scores were calculated. Model interpretability was assessed using SHAP values for the best-performing model (XGBoost). Global feature importance and feature effects were visualized using SHAP summary (beeswarm) plots generated from the external validation dataset. All analyses used Python (v3.12.11) with scikit-learn (v1.7.2), XGBoost (v3.1.1), CatBoost (v1.2.5), Optuna (v4.6.0), and SHAP (v0.50.0). Model calibration was additionally assessed using the Brier score and a reliability diagram (decile-binned calibration curve) on the external validation cohort, and the clinical utility of the model was evaluated using Decision Curve Analysis (DCA) across threshold probabilities from 0 to 80%. To illustrate the nonlinear predictor–outcome relationships identified by XGBoost, SHAP dependence plots were generated for lymphocyte count and age. Sensitivity analysis We performed a sensitivity analysis using the best-performing XGBoost model to see how much objective lab and radiologic data could help with prognosis. Two reduced-feature models were developed and compared to the comprehensive model. One was a clinical-features-only model that was trained only on demographics and symptom profiles. The other was a laboratory-and-radiologic-features-only model that used lab values and chest radiograph findings without any clinical history. Both reduced models were optimized using the same methodology as the comprehensive model. In addition, because three key laboratory predictors (serum albumin, hemoglobin, and lymphocyte count) exceeded the 5% threshold for non-negligible missingness, we performed an imputation sensitivity analysis in which the XGBoost model was retrained using Multiple Imputation by Chained Equations (MICE; scikit-learn IterativeImputer, 20 iterations) instead of median imputation, following the identical Bayesian-optimization and F2-threshold pipeline. A parsimonious 5-variable XGBoost model restricted to the top five predictors ranked by mean absolute SHAP value (serum albumin, hemoglobin, lymphocyte count, age, sex) was also developed and externally validated to evaluate whether a clinically streamlined model could achieve comparable performance to the full 18-variable model. Results Participant flow and descriptive data The final study population consisted of 1580 patients, of whom 1471 (93.1%) had favorable outcomes and 109 (6.9%) had unfavorable outcomes (Table 1). The Training Set had a significantly higher mean age (61.1 ± 17.2 vs. 57.5 ± 20.7 years, p = 0.024), higher median lymphocytes (22.7% vs. 19.6%, p = 0.007) and creatinine (0.77 vs. 0.72 mg/dL, p = 0.017), and markedly higher prevalence of cavitary lesions (14.5% vs. 4.2%, p < 0.001) compared to the External Validation Set. Significant differences were observed in sputum smear grades (p = 0.013) and lung involvement laterality (p < 0.001). The External Validation Set showed higher frequencies of respiratory symptoms (61.05% vs. 49.71%, p = 0.004) and alarming symptoms (45.3% vs. 26.3%, p < 0.001). Alcohol use was more common in the Training Set (48.8% vs. 40.5%, p = 0.040). No significant differences were observed in sex, BMI, serum albumin, hemoglobin, comorbidities, or smoking history. Table 1Baseline characteristics of newly diagnosed patients with drug-susceptible pulmonary tuberculosis according to datasetVariableOverallExternal validation setTraining setp-value(n = 1,580)(n = 190)(n = 1,390)Age, years60.7±17.757.5±20.761.1±17.20.024Sex Male987 (62.5)111 (58.4)876 (63.0)0.251 Female593 (37.5)79 (41.6)541 (37.0)History of smoking828 (52.4)94 (49.5)734 (52.8)0.432History of alcohol use755 (47.8)77 (40.5)678 (48.8)0.040Body mass index, kg/m221.8±3.321.7±3.521.8±3.30.800Comorbidities Diabetes mellitus388 (24.6)41 (21.6)347 (25.0)0.354 Chronic pulmonary disease81 (5.1)13 (6.8)68 (4.9)0.333 Chronic kidney disease46 (2.9)1 (0.5)45 (3.2)0.064Sputum AFB smear grade Negative1151 (72.9)158 (83.2)993 (71.4)0.013 Scanty30 (1.9)2 (1.1)28 (2.0) 1 + 173 (11.0)18 (9.5)155 (11.2) 2 + 95 (6.0)6 (3.2)89 (6.4) 3 + 88 (5.6)3 (1.6)85 (6.1) 4 + 43 (2.7)3 (1.6)40 (2.9)Cavitary lesion on CXR209 (13.2)8 (4.2)201 (14.5) < 0.001Lung involvement on CXR None244 (15.4)55 (29.0)189 (13.6) < 0.001 Unilateral960 (60.8)99 (52.1)861 (61.9) Bilateral376 (23.8)36 (19.0)340 (24.5)TB-related symptoms Respiratory symptoms807 (51.1)116 (61.1)691 (49.7)0.004 Alarming symptoms451 (28.5)86 (45.3)365 (26.3) < 0.001 Constitutional symptoms437 (27.7)60 (31.6)377 (27.1)0.229Laboratory findings Hemoglobin, g/dL12.8 (11.5–14.1)12.8 (11.4–14.0)12.9 (11.5–14.2)0.260 Lymphocyte count, %22.1 (15.0–29.6)19.6 (12.7–28.4)22.7 (15.3–29.8)0.007 Serum albumin, g/dL4.00 (3.50–4.40)4.00 (3.30–4.50)4.00 (3.59–4.40)0.289 Serum creatinine, mg/dL0.77 (0.63–0.91)0.72 (0.60–0.91)0.77 (0.63–0.91)0.017Unfavorable outcome109 (6.9)15 (7.9)94 (6.8)0.542AFB acid-fast bacilli, CXR chest X-ray, SD standard deviation, IQR interquartile rangeContinuous variables are presented as mean (standard deviation) or median (interquartile range). Categorical variables are presented as number (percentage)Missing values were as follows: lymphocyte count (n = 129), serum albumin (n = 172), serum creatinine (n = 133), hemoglobin (n = 127), and body mass index (n = 31) Baseline characteristics of newly diagnosed patients with drug-susceptible pulmonary tuberculosis according to dataset AFB acid-fast bacilli, CXR chest X-ray, SD standard deviation, IQR interquartile range Continuous variables are presented as mean (standard deviation) or median (interquartile range). Categorical variables are presented as number (percentage) Missing values were as follows: lymphocyte count (n = 129), serum albumin (n = 172), serum creatinine (n = 133), hemoglobin (n = 127), and body mass index (n = 31) Predictive performance of machine learning models Among the six models evaluated on the external validation cohort (Table 2), XGBoost demonstrated the highest discriminative ability with an AUROC of 0.818 (95% CI 0.323–1.000) and an AUPRC of 0.432 (Fig. 2, Supplemental Figure S1). The standard logistic regression model achieved an AUROC of 0.758 (95% CI 0.169–1.000) and an AUPRC of 0.251, which were lower than those of the ML models. While Logistic Lasso, ExtraTrees, XGBoost, and MLP all achieved 80.0% sensitivity at F2-optimized thresholds, ExtraTrees exhibited the lowest specificity (65.1%) compared to XGBoost (72.6%). Table 2Performance of machine learning models for predicting unfavorable anti-tuberculosis treatment outcomes in the external validation cohort; (A) discrimination and classification performance of machine learning models, and (B) Risk stratification metrics of machine learning modelsModelThresholdF2-scoreAUROC (95% CI)AUPRCSensitivitySpecificityPrecisionNPV(A) Logistic regression0.500.758 (0.17—1.00)0.25100.9900.921 Logistic Lasso0.090.4960.756 (0.16–1.00)0.2650.800.720.1970.977 ExtraTrees0.080.4510.783 (0.37–1.00)0.2410.800.650.1640.974 CatBoost0.100.4420.789 (0.29–1.00)0.3730.670.750.1890.964 XGBoost0.080.5000.818 (0.32–1.00)0.4320.800.730.2000.977 MLP0.090.4880.764 (0.22–1.00)0.2530.800.710.1900.976ModelPrecision @5%Recall @5%Precision @10%Recall @10%Precision @20%Recall @20%(B) Logistic Regression0.3330.20.2630.3330.2630.667 Logistic Lasso0.1110.0670.3160.4000.2630.667 ExtraTrees0.3330.2000.1580.2000.2110.533 CatBoost0.4440.2670.3160.4000.2370.600 XGBoost0.5560.3330.3680.4670.2890.733 MLP0.2220.1330.3680.4670.2370.600AUROC area under the receiver-operating characteristic curve, CI confidence interval, AUPRC area under the precision–recall curve, PPV positive predictive value (precision), NPV negative predictive value, MLP multi-layer perceptronModels were optimized to maximize the F2 score to prioritize sensitivity. “Recall @ Top K%” indicates the proportion of actual unfavorable outcomes identified when screening the top K% of patients with the highest predicted risk scores. The XGBoost model demonstrated superior screening utility Performance of machine learning models for predicting unfavorable anti-tuberculosis treatment outcomes in the external validation cohort; (A) discrimination and classification performance of machine learning models, and (B) Risk stratification metrics of machine learning models AUROC area under the receiver-operating characteristic curve, CI confidence interval, AUPRC area under the precision–recall curve, PPV positive predictive value (precision), NPV negative predictive value, MLP multi-layer perceptron Models were optimized to maximize the F2 score to prioritize sensitivity. “Recall @ Top K%” indicates the proportion of actual unfavorable outcomes identified when screening the top K% of patients with the highest predicted risk scores. The XGBoost model demonstrated superior screening utility Receiver-Operating Characteristic (ROC) curves of machine learning models on the external validation set. The ROC curves compare the discriminative performance of five machine learning models—logistic Lasso, ExtraTrees, CatBoost, XGBoost, and multi-layer perceptron (MLP)—in predicting unfavorable tuberculosis treatment outcomes. The XGBoost model (red line) demonstrated the highest performance with an Area Under the Curve (AUROC) of 0.818, followed by CatBoost (green line, AUROC = 0.789), ExtraTrees (orange line, AUROC = 0.783), MLP (purple line, AUROC = 0.764), and Logistic Lasso (blue line, AUROC = 0.756). The dashed diagonal line represents the performance of a random classifier At the F2-optimized threshold of 0.08, the XGBoost model achieved 80.0% sensitivity, 72.6% specificity, and 97.7% NPV. Screening the top 10% of high-risk patients captured 46.7% of all unfavorable outcomes; expanding to the top 20% captured 73.3% (Supplemental Figure S2). In comparison, the standard logistic regression model captured 33.3% at the top 10% and 66.7% at the top 20%. The XGBoost model was well calibrated on the external validation cohort, with a Brier score of 0.061 and a reliability diagram tracking the diagonal of perfect calibration (Supplemental Figure S3). Decision Curve Analysis demonstrated that the XGBoost model provided a positive net benefit over both the “treat all” and “treat none” strategies across a clinically relevant range of threshold probabilities (approximately 2%–30%), supporting its clinical utility for risk stratification (Supplemental Figure S4). Logistic regression analysis In univariate analysis (Supplemental Table S4), significant associations with unfavorable outcomes were found for older age (p < 0.001), lower BMI (p = 0.007), diabetes mellitus (p = 0.010), higher sputum smear grades (2 + and 3 + ; p < 0.05), lower lymphocyte count (p < 0.001), constitutional (p < 0.001) and alarming symptoms (p = 0.003), bilateral lung involvement (p < 0.001), lower serum albumin (p < 0.001), lower hemoglobin (p < 0.001), and higher creatinine (p = 0.011). In multivariate analysis, serum albumin was the strongest predictor (aOR, 0.492; 95% CI 0.325–0.743; p < 0.001). Hemoglobin (aOR, 0.858; 95% CI 0.756–0.973; p = 0.017) and female sex (aOR, 0.589; 95% CI 0.359–0.967; p = 0.037) demonstrated a significant protective effect. Lymphocyte count (aOR, 0.973; 95% CI 0.947–1.001; p = 0.059) and age (aOR, 1.01; 95% CI 0.998–1.028; p = 0.097) showed borderline significance. Sensitivity analysis: feature set comparison To evaluate the prognostic significance of each feature domain, we compared the optimal XGBoost model across three feature sets utilizing the external validation cohort (Supplemental Table S5, Supplemental Figure S5). The clinical-features-only XGBoost model showed a considerably lower AUROC of 0.732 (95% CI 0.202–1.000) and AUPRC of 0.206 than the comprehensive model, which had an AUROC of 0.818 and an AUPRC of 0.432. This performance difference was more pronounced when it came to risk stratification metrics. The clinical-features-only model only picked up 13.3% of unfavorable outcomes in the top 5% (Recall@5%) and 53.3% in the top 20% (Recall@20%). The comprehensive model, on the other hand, picked up 33.3% and 73.3%, respectively. In contrast, the laboratory-and-radiologic-features-only XGBoost model achieved an AUROC of 0.821 (95% CI 0.372–1.000), comparable to the comprehensive model. However, despite the similar overall discriminative ability, the comprehensive model demonstrated superior screening performance: at the top 5% threshold, the comprehensive model captured 33.3% of unfavorable outcomes with a precision of 55.6%, whereas the laboratory-and-radiologic-only model captured 20.0% with a precision of 33.3%. At the top 20% threshold, the comprehensive model identified 73.3% of all unfavorable outcomes compared with 66.7% for the laboratory-and-radiologic-only model. The feature importance analysis of the clinical-features-only model (Supplemental Figure S6) indicated that constitutional symptoms and age were the most significant predictors, followed by body mass index, alarming symptoms, and diabetes mellitus. However, these clinical and demographic features alone showed markedly inferior discriminative and screening performance compared to models which utilized objective physiological markers. A parsimonious XGBoost model restricted to the top five SHAP-ranked predictors (serum albumin, hemoglobin, lymphocyte count, age, and sex) retained discriminative performance comparable to the full 18-variable model (AUROC 0.806 vs. 0.815; AUPRC 0.422 vs. 0.386; Brier 0.060 vs. 0.061; sensitivity 0.800 in both), with a modest reduction in specificity (0.651 vs. 0.731) (Supplemental Table S6). An imputation sensitivity analysis using MICE in place of median imputation yielded broadly comparable performance (AUROC 0.777; AUPRC 0.427; Brier 0.062), supporting the robustness of our findings to the choice of imputation strategy (Supplemental Table S7). Feature importance SHAP analysis of the XGBoost model revealed serum albumin as the most important predictor, succeeded by hemoglobin, lymphocyte count, and age (Fig. 3). The SHAP beeswarm plots showed that lower serum albumin, hemoglobin, and lymphocyte counts, alongside older age, were associated with higher predicted probability of unfavorable outcomes. There was a positive correlation between lung involvement and diabetes mellitus and a higher risk. These features were highly consistent with the independent predictors identified through multivariate logistic regression. Feature importance analysis using SHapley Additive exPlanations (SHAP) for the XGBoost model. a SHAP beeswarm plot showing the impact of individual feature values on the model output. Each dot represents a patient. Red color indicates a high value of the feature, while blue indicates a low value. Points to the right of the central line indicate a higher predicted probability of an unfavorable outcome. b SHAP mean bar plot ranking the features by their mean absolute SHAP value, representing the average magnitude of their impact on the model prediction. Serum albumin, hemoglobin, lymphocyte count, and age were identified as the most dominant predictors. CXR: chest X-ray Discussion In this multicenter prospective cohort study, we trained and externally validated ML models for predicting unfavorable treatment outcomes in patients with drug-susceptible pulmonary TB. The XGBoost model achieved the greatest AUROC of 0.818, outperformed classical logistic regression and other machine learning algorithms, in line with the recent literature [10]. Both nonlinear ML (SHAP values) and linear statistical analyses have determined serum albumin, hemoglobin, and lymphocyte count as the most critical prognostic determinants [11, 12]. These results highlight that baseline nutritional status and systemic immune resilience dictate the trajectory of treatment even in high-income settings [13, 14]. Our comparative sensitivity analysis emphasizes the absolute necessity of objective laboratory and radiological data, specifically regarding screening applicability for class-imbalanced outcomes. Despite the AUROC of the laboratory-and-radiologic-only model being similar to that of the comprehensive model, the comprehensive model showed significantly superior performance in risk stratification measures, such as recall@top-K%, which are more clinically relevant for recognizing rare, unfavorable outcomes. Notably, the clinical feature-only model showed a substantially lower AUROC and markedly lower screening performance, where in the top 20% threshold only 53.3% of unfavorable outcomes were captured compared with 73.3% for the complete model. These results indicate AUROC results may not fully capture the additional-efficiency benefits of addition of objective biomarkers and the improvement of population-level enrichment measures better reflect the practical use of laboratory data for selecting high-risk patients for targeted intervention. The robust association of lower serum albumin, hemoglobin, and lymphocyte counts with unfavorable outcomes underlines the importance of the physiological reserves of host [10, 15]. For example, serum albumin, the most important factor in both the SHAP analysis and multivariate regression (aOR 0.49), likely reflects a composite of nutritional intake and stress from chronic inflammation [13, 16]. Notably, lymphocyte count and age were among the top four predictors in XGBoost, despite showing only borderline significance in the linear model (p = 0.059 and p = 0.097), suggesting that these variables exert influence through complex nonlinear interactions that traditional regression fails to capture [11, 17]. SHAP dependence plots further visualized these nonlinear associations, as the effect of lymphocyte count on predicted risk increased appreciably below ∼20% and plateaued above 30% (Supplemental Figure S7) and age had little effect below ∼50 years and increased markedly after 65–70 years (Supplemental Figure S8) indicating both immunosenescence and the increased comorbidity burden among older TB patients. By calibrating XGBoost to attain a maximum F2 score, an NPV of 97.7% was achieved and therefore low-risk patients could be clearly excluded. The model’s enrichment capability, which captures nearly three-quarters of the unfavorable outcomes by screening the top 20%, suggests that intensive interventions, such as nutritional support or closer monitoring, can be strategically targeted to patients with higher need [18, 19]. Of note, a parsimonious model limited to only the top 5 SHAP-ranked variables (serum albumin, hemoglobin, lymphocyte count, age, sex) showed discrimination and calibration comparable to those of the complete 18-variable model, indicating that a clinically simplified risk score based on three standard laboratory values as well as age and sex might be especially applicable to resource-constrained settings where comprehensive baseline data acquisition is challenging. A comparison with standard logistic regression further underscores the advantages of the ML-based threshold optimization. At a conventional threshold of 0.5, no positive cases were detected by employing the logistic regression, indicating that a fixed decision boundary was unsuitable for imbalanced datasets. In contrast, the ML models with F2-optimized thresholds achieved substantially higher sensitivity and negative predictive value while maintaining clinically acceptable specificity. In the tier of 20% risk, by comparing the two models, XGBoost achieved 73.3% sensitivity against 66.7% for logistic regression indicating that ML methods were superior for screening. Our findings are consistent with prior ML studies on TB prognosis while demonstrating methodological advances. Chinagudaba et al. [20] employed XGBoost to predict TB treatment outcomes (AUC-ROC 0.95), but relied on programmatic and demographic variables without laboratory biomarkers. Peng et al. [21] examined TB-diabetes comorbidities in particular using ML with SHAP analysis, identifying coagulation parameters as key predictors in this subpopulation. Peetluk et al. [22] proposed a logistic regression-based prediction model in a Brazilian cohort (C-statistic 0.77) with hemoglobin as a predictor, as reported by our study. Our work is unique in that it employs a multicenter prospective design, is externally validated with a large number of studies, and sensitivity analysis validates the centrality of laboratory data, and uses ML and conventional regression to cross-validate predictors. There are multiple limitations to this study that we must bear in mind. There may be selection bias with the exclusion of patients lost to follow-up and patients with drug-resistant tuberculosis, limiting the generalizability of our findings to a wider spectrum of TB patients. A direct comparison of the 1,580 included patients with the 109 patients who were lost to follow-up or transferred-out showed that the latter were significantly older and had lower BMI, lymphocyte count, serum albumin, and hemoglobin (all p ≤ 0.031), and more frequently reported constitutional symptoms (all comparisons in Supplemental Table S1). Because several of these variables are also the strongest SHAP-identified predictors of unfavorable outcome, residual survivorship bias cannot be excluded: patients at highest baseline risk may have been disproportionately lost from the analytic cohort. Reassuringly, serum creatinine and the core comorbidity and symptom variables did not differ between the groups, and because the lost to follow-up/transferred-out patients were skewed toward high-risk profiles, the predictive relationships reported here are likely to remain valid—or even strengthen—in a more representative cohort. Also, as external validation was conducted at a single institution, potentially restricting the assessment of geographic heterogeneity, this concern was exacerbated. Because the composite endpoint in the present study included many heterogeneous clinical events, it was possible that the predictive specificity of individual components may have been reduced. Moreover, the relatively small number of unfavorable events in the external cohort yielded wide confidence intervals for the AUROC, necessitating the need for larger validation studies. On methodological grounds, the lack of centralized laboratory standardization may have led to inter-site variability of the analysis. Moreover, the reliance on median imputation for missing values could potentially introduce bias if the data were not missing completely at random, although a sensitivity analysis using MICE yielded broadly comparable discrimination and calibration, supporting the robustness of our findings to the choice of imputation strategy. This study was conducted in 23 hospitals in Korea within a well-structured TB management system. Although external validation supports model generalizability within similar settings, caution is warranted when extrapolating to low- or high-burden settings with different patient demographics and healthcare infrastructures. Conclusion Standard inexpensive low-cost laboratory markers, such as serum albumin, hemoglobin, and lymphocyte count, are powerful independent predictors of TB outcomes. The XGBoost model is an actionable approach to individualized TB treatment and provides significant performance advantages over models that rely only on clinical symptoms and demographic variables. Future efforts should focus on integrating this risk score into the electronic health records to guide prospective biomarker-driven interventions. Supplementary Information Supplementary Material 1. Acknowledgements We would like to express our sincere appreciation to Yousang Ko (Kangdong Sacred Heart Hospital), Do Jin Kim (Soonchunhyang University Bucheon Hospital), Ganghee Chae (Ulsan University Hospital), Sun Young Kyung (Gachon University Gil Hospital), Tai Joon An (Yeouido St. Mary’s Hospital), Yong-Soo Kwon (Chonnam National University Hospital), Ock-Hwa Kim (Chungnam National University Sejong Hospital), Won Yeon Lee (Wonju Christian Hospital), and Saerom Kim (Pusan National University Hospital) for their valuable contributions to this work. We also gratefully acknowledge the staff members involved in the COSMOTB and SAFE-TB studies, especially Seo Yun Jeong, RN, for their invaluable support and assistance. Abbreviations Adjusted odds ratio Area under precision–recall curve Area Under the Receiver-Operating Characteristic Curve Body mass index Confidence interval Cohort Study of Pulmonary Tuberculosis Chest X-ray Isoniazid, rifampicin, ethambutol, and pyrazinamide Institutional Review Board Least absolute shrinkage and selection operator Machine learning Multi-layer perceptron Negative predictive value Receiver Operating Characteristic Surveillance of Side Effects during Anti-TB Treatment SHapley Additive exPlanations Tuberculosis Author contributions Taehyung Lee: Conceptualization, Software, Formal analysis, Investigation, Validation, Writing—Original Draft, Writing—Review & Editing Inseo Choi: Methodology, Data curation, Writing—Review & Editing Hoyoun Lee: Methodology, Data curation, Writing—Review & Editing Hyung Woo Kim: Conceptualization, Methodology, Data curation, Resources, Writing—Review & Editing Eung Gu Lee: Data curation, Investigation, Writing—Review & Editing Yeonhee Park: Data curation, Investigation, Writing—Review & Editing Sung Soo Jung: Data curation, Investigation, Writing—Review & Editing Jin Woo Kim: Data curation, Investigation, Writing—Review & Editing Jee Youn Oh: Data curation, Investigation, Writing—Review & Editing Heayon Lee: Data curation, Investigation, Writing—Review & Editing Seung Hoon Kim: Data curation, Investigation, Writing—Review & Editing Sun-Hyung Kim: Data curation, Investigation, Writing—Review & Editing Jiwon Lyu: Data curation, Investigation, Writing—Review & Editing Sun Jung Kwon: Data curation, Investigation, Writing—Review & Editing Yun-Jeong Jeong: Data curation, Investigation, Writing—Review & Editing Hyeon-Kyoung Koo: Data curation, Investigation, Writing—Review & Editing Ju Sang Kim: Conceptualization, Data curation, Methodology, Project administration, Resources, Writing—Review & Editing Jinsoo Min: Conceptualization, Data Curation, Formal analysis, Funding acquisition, Investigation, Methodology, Project administration, Resources, Supervision, Validation, Visualization, Writing—Original Draft, Writing—Review & Editing. Funding This study work was supported by the Research Program funded by the Korea National Institute of Health (2026E200100, 2025E200100). The funder had no role in the study design, data collection and analysis, decision to publish, or preparation of the manuscript. Data availability The data that support the findings of this study are available from Korea Disease Control and Prevention Agency and Korea National Institute of Health; however, restrictions apply. Data will be provided by the corresponding author upon reasonable request and with permission of Korea Disease Control and Prevention Agency. Declarations Ethics approval and consent to participate This study used data derived from four prospective tuberculosis cohort studies. All studies were conducted in accordance with the principles of the Declaration of Helsinki and were approved by the respective institutional review boards. The COSMOTB pilot phase (2016–2018) protocol was approved by the Institutional Review Board of Chungbuk National University Hospital (No. 2016-10-003). The COSMOTB phase 1 study (2019–2021) was approved by the Institutional Review Board of the Catholic University of Korea (IRB No. C19ONDI0458), and the subsequent COSMOTB phase 2 study (2022–2024) was approved by the same institution (IRB No. XC22ENDI0023). The SAFE-TB study (2020–2022) was approved by the Institutional Review Board of the Catholic University of Korea (IRB No. XC20ENDI0086). Written informed consent was obtained from all participants prior to enrollment. Competing interests The authors declare no competing interests. Footnotes Publisher's Note Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations. References Associated Data Supplementary Materials Supplementary Material 1. Data Availability Statement The data that support the findings of this study are available from Korea Disease Control and Prevention Agency and Korea National Institute of Health; however, restrictions apply. Data will be provided by the corresponding author upon reasonable request and with permission of Korea Disease Control and Prevention Agency.