Skip to main content
BMC Infectious Diseases logoLink to BMC Infectious Diseases
. 2026 Mar 27;26:901. doi: 10.1186/s12879-026-13173-1

A machine learning-based prediction model for treatment efficacy in smear and/or chest X-ray positive tuberculosis patients

Xiaohua Cui 1,#, Wei Fu 1,#, Xuan Wu 1, Zhe Peng 1, Wentao Wu 1,2,✉
PMCID: PMC13147690  PMID: 41888694

Abstract

Objective

To develop a machine learning (ML)-based prediction model for tuberculosis (TB) treatment failure, and evaluate the predictive performance and clinical utility.

Methods

Patients were randomly allocated to a training set and a validation set in a 7:3 ratio. Data collected included demographic characteristics, clinical features, and laboratory parameters. Univariate analysis and binary logistic regression were applied to the training set to identify factors associated with treatment outcome. Based on common predictive modeling standards, an AUC > 0.8 was considered good, and > 0.9 was considered excellent. Three prediction models—Random Forest (RF), Support Vector Machine (SVM), and K-Nearest Neighbors (KNN)—were constructed. Model performance was evaluated based on accuracy, precision, recall, F1-score, and the area under the receiver operating characteristic curve (AUC).

Results

Among 541 enrolled patients, 133 (24.58%) experienced treatment failure (92 [24.27%] in the training set and 41 [25.31%] in the validation set).Cavitation, diabetes comorbidity, radiographic disease extent, TB type (pulmonary vs. extrapulmonary), lymphocyte percentage (LYMPH%), and serum albumin (ALB) level were identified as significant predictors of treatment outcome (P < 0.05). The RF, SVM, and KNN models achieved AUC values of 0.783, 0.707, and 0.668, respectively.

Conclusion

The ML-based prediction model shows fair to good predictive performance (AUC up to 0.783), suggesting potential clinical utility with further validation. This model may assist in early risk stratification and support individualized treatment planning for tuberculosis patients.

Clinical trial number

Not applicable.

Supplementary Information

The online version contains supplementary material available at 10.1186/s12879-026-13173-1.

Keywords: Tuberculosis, Machine learning, Treatment outcome, Prediction model, Logistic regression

Introduction

Tuberculosis (TB), a chronic infectious disease caused by Mycobacterium tuberculosis, remains a significant global public health challenge [1]. Despite the widespread implementation of standardized anti-TB chemotherapy regimens, treatment failure, drug resistance, and recurrence persist in a subset of patients. These adverse outcomes, collectively referred to as “poor treatment outcomes”—which refer to treatment failure (persistent positive pathogens, lesion progression, or unimproved symptoms), drug resistance, or recurrence during or after standardized treatment—not only increase the risk of disease transmission but also impose substantial burdens on patient prognosis and healthcare resources. Studies indicate that a significant proportion of TB patients experience poor treatment outcomes even under standardized therapy [2]. Consequently, the early identification of high-risk individuals and timely adjustment of treatment strategies are critical for improving cure rates and mitigating the development of drug resistance [2].Despite the urgent need to improve treatment outcomes, traditional prediction methods have inherent limitations in addressing the complexity of TB treatment. Traditional approaches to predicting TB treatment outcomes have predominantly relied on methods such as univariate analysis or logistic regression. While these techniques can identify potential risk factors, they often fail to capture the complex non-linear relationships and interactions among diverse clinical variables. The advent of large-scale medical data, however, has propelled machine learning (ML) to the forefront of complex disease prognosis prediction [3, 4]. “Machine learning is a branch of artificial intelligence that enables algorithms to learn patterns from data and make predictions without explicit programming, which is particularly suitable for analyzing complex non-linear relationships among multiple clinical variables.” ML algorithms offer powerful capabilities for pattern recognition and non-linear modeling, enabling the extraction of underlying patterns from multidimensional clinical data to construct more accurate predictive tools. These methods have demonstrated considerable promise in fields such as oncology and cardiovascular disease [5].Given the limitations of traditional methods and the potential of machine learning, this study aims to develop a more accurate prediction model for TB treatment failure. However, the ML-based prediction model for predicting anti-TB treatment outcome remains relatively limited. Therefore, this study aims to develop an ML-based prediction model encompassing patient demographics, clinical manifestations, and laboratory and radiographic findings for TB treatment outcome. We aim to provide a scientific tool for the early and accurate prediction of TB treatment outcomes and the formulation of individualized treatment plans.

Materials and methods

Research subjects

Patients who received standardized anti-TB treatment at our hospital were enrolled. All patients met the diagnostic criteria for TB [6], confirmed by sputum smear acid-fast staining or chest imaging. Written informed consent was obtained from all participants, and the study was approved by the ethics committee of Henan Chest Hospital. Inclusion criteria were: (1) aged 18–75 years; (2) diagnosed with TB, including new or previously treated patients; (3) receiving standardized anti-TB treatment (new patients: 2HRZE/4HR; retreatment patients: 2HRZES/6HRE; H: isoniazid, R: rifampicin, Z: pyrazinamide, E: ethambutol, S: streptomycin); (4) availability of complete pre-treatment and treatment data. Exclusion criteria were: (1) severe dysfunction of vital organs (heart, liver, kidneys); (2) human immunodeficiency virus (HIV) infection or acquired immunodeficiency syndrome (AIDS); (3) mental illness or cognitive impairment hindering treatment cooperation; (4) allergy to anti-TB drugs; (5) treatment withdrawal or loss to follow-up. Patients were randomly assigned to a training set (n = 379) or a validation set (n = 162) in a 7:3 ratio.

Data collection

Data were collected from the electronic medical record system and patient follow-up records. Demographic characteristics included age, gender, body mass index (BMI), smoking history (yes/no), and alcohol consumption history (yes/no). Clinical indicators comprised TB type (primary/secondary/hematogenous disseminated/tuberculous pleurisy), lesion scope (unilateral/bilateral), cavity formation (yes/no), comorbid diabetes (yes/no), comorbid hypertension (yes/no), pre-treatment cough severity (severe/moderate/mild), and pre-treatment hemoptysis (yes/no). Pre-treatment laboratory data collected included white blood cell count (WBC), neutrophil percentage (NEUT%), lymphocyte percentage (LYMPH%), hemoglobin (Hb), platelet count (PLT), serum albumin (ALB), alanine transaminase (ALT), aspartate transaminase (AST), serum creatinine (SCr), and sputum smear acid-fast staining results (positive/negative).

Treatment outcome evaluation

Treatment outcome was evaluated upon treatment completion (6 months for new patients, 8 months for retreatment patients) based on clinical symptoms, chest imaging findings, and sputum bacteriological examination results. Treatment was defined as effective if clinical symptoms (e.g., cough, hemoptysis) showed ≥ 80% improvement or complete resolution (assessed by the physician based on symptom frequency and intensity), chest imaging revealed substantial lesion absorption (≥ 50% reduction in lesion area), fibrosis, or calcification, and sputum smear acid-fast staining or culture was negative. Treatment was defined as ineffective if clinical symptoms showed no significant improvement or worsened, chest imaging showed no significant change or progression of lesions, and sputum smear acid-fast staining or culture remained positive.

Pre-treatment cough symptom evaluation was based on patient self-reporting combined with physician assessment. Patients described cough frequency, intensity, and impact on daily life. Physicians categorized cough severity as “severe”, “moderate”, or “mild” based on patient descriptions and physical examination findings: Severe: Frequent, intense cough significantly disrupting sleep, work, and daily activities; Moderate: Occasional cough causing noticeable but tolerable interference with daily life; Mild: Infrequent, mild cough with minimal or no impact on daily activities.

Statistical analysis

Statistical analysis was performed using SPSS 26.0 software. Categorical data are presented as number and percentage (%), and compared using the χ² test. Normally distributed continuous data are presented as mean ± standard deviation (x̄ ± s), and compared using the t-test. Binary logistic regression analysis was used to identify factors influencing TB treatment outcome; statistical significance was set at P < 0.05. Additionally, prediction models employing Random Forest (RF), Support Vector Machine (SVM), and K-Nearest Neighbors (KNN) algorithms were constructed using Python 3.8.5 and the scikit-learn library. Model hyperparameters were optimized using five-fold cross-validation on the training set, and model performance was subsequently evaluated based on the validation set. To assess the generalizability of the models, metrics including accuracy, precision, recall, F1-score, and the area under the receiver operating characteristic curve (AUC) were calculated on the validation set. Based on common predictive modeling standards, an AUC > 0.8 was considered good, and > 0.9 was considered excellent.

Results

Baseline characteristics and treatment outcomes

A total of 541 TB patients were enrolled and randomly divided into training (n = 379) and validation (n = 162) sets, with no significant differences in baseline characteristics between the two sets (all P > 0.05), ensuring comparability; the overall treatment failure rate was 24.58%, with consistent failure type distributions in both sets.

A total of 541 TB patients who met the inclusion criteria were enrolled and randomly assigned to a training set (n = 379) or a validation set (n = 162) in a 7:3 ratio. Treatment outcomes showed that 287 (75.73%) patients in the training set achieved effective treatment, and 92 (24.27%) had treatment failure; in the validation set, 121 (74.69%) had effective treatment and 41 (25.31%) had treatment failure.

Stratification by failure type revealed: in the training set, 53 (57.61%) cases were persistent positive sputum smear/culture, 26 (28.26%) were lesion progression, and 13 (14.13%) were unimproved/worsened clinical symptoms; in the validation set, 23 (56.10%) cases were persistent positive sputum smear/culture, 12 (29.27%) were lesion progression, and 6 (14.63%) were unimproved/worsened clinical symptoms.

Comparisons of baseline indicators (age, gender, BMI, smoking history, alcohol consumption history, TB type, lesion scope, cavity formation, comorbidities, pre-treatment symptoms, and laboratory parameters) between the two sets showed no statistically significant differences (all P > 0.05) (Table 1).

Table 1.

Comparison of general data between the training set and the validation set

Indicators Training set (n = 379) Validation set (n = 162) t/χ² P
Age (years) 43.56 ± 12.79 44.16 ± 13.08 0.496 0.619
BMI (kg/m²) 23.58 ± 3.19 23.80 ± 3.26 0.729 0.465
Sex (Male/Female) 221/158 98/64 0.223 0.636
Smoking history (Yes/No) 127/252 56/106 0.056 0.811
Drinking history (Yes/No) 89/290 40/122 0.091 0.762
Types of pulmonary tuberculosis Tuberculous pleurisy 22(5.80) 12(7.41) 0.522 0.913
Primary 35(9.23) 14(8.64)
Secondary 298(78.63) 126(77.78)
Hematogenous disseminated 24(6.33) 10(6.17)
Lesion scope (Unilateral/Bilateral) 155/224 62/100 0.325 0.568
Cavity formation (Yes/No) 112/267 47/115 0.015 0.899
Complicated with diabetes (Yes/No) 58/321 23/139 0.109 0.741
Complicated with hypertension (Yes/No) 76/303 31/131 0.060 0.806
Cough symptoms before treatment Severe 45(11.87) 20(12.35) 0.069 0.966
Moderate 187(49.34) 78(48.15)
Mild 147(38.79) 64(39.51)
Hemoptysis symptoms before treatment (Yes/No) 69/310 26/136 0.346 0.546
WBC (×10⁹/L) 6.85 ± 2.14 6.92 ± 2.21 0.345 0.730
NEUT% (%) 65.80 ± 10.21 66.23 ± 10.51 0.444 0.656
LYMPH% (%) 26.56 ± 8.33 25.81 ± 8.56 0.951 0.341
HB (g/L) 125.61 ± 15.83 124.84 ± 16.27 0.513 0.607
PLT (×10⁹/L) 215.60 ± 56.82 218.35 ± 58.26 0.511 0.609
ALB (g/L) 40.54 ± 5.24 39.83 ± 5.51 1.421 0.155
ALT (U/L) 28.62 ± 12.31 29.33 ± 13.11 0.602 0.547
AST (U/L) 27.86 ± 11.53 28.50 ± 12.20 0.581 0.561
SCr (µmol/L) 78.55 ± 15.61 79.23 ± 16.31 0.457 0.647
Sputum smear acid-fast staining (Positive/Negative) 189/190 82/80 0.025 0.873

Univariate analysis of influencing factors for TB treatment efficacy

Univariate analysis identified six factors significantly associated with treatment failure: cavitation, comorbid diabetes, lesion scope (bilateral), TB type, lymphocyte percentage (LYMPH%), and serum albumin (ALB) level (all P < 0.05); other factors showed no significant correlation.

Univariate analysis was performed on the training set to compare differences in clinical and laboratory indicators between the effective and ineffective treatment groups. The results showed that cavity formation (χ²=5.564, P = 0.018), comorbid diabetes (χ²=8.813, P = 0.003), lesion scope (bilateral vs. unilateral, χ²=5.637, P = 0.017), TB type (χ²=11.077, P = 0.011), LYMPH% (t = 2.720, P = 0.006), and ALB level (t = 3.006, P = 0.002) were significantly different between the two groups.

In contrast, age, BMI, gender, smoking history, alcohol consumption history, comorbid hypertension, pre-treatment cough severity, pre-treatment hemoptysis, white blood cell count (WBC), neutrophil percentage (NEUT%), hemoglobin (Hb), platelet count (PLT), alanine transaminase (ALT), aspartate transaminase (AST), serum creatinine (SCr), and sputum smear acid-fast staining results showed no statistically significant differences between the two groups (all P > 0.05) (Table 2).

Table 2.

Univariate analysis of influencing factors for ineffective treatment of pulmonary tuberculosis

Indicators Effective group (n = 287) Ineffective group (n = 92) t/χ² P
Age (years) 42.35 ± 12.64 44.82 ± 13.15 1.615 0.107
BMI (kg/m²) 23.72 ± 3.22 23.21 ± 3.08 1.335 0.182
Sex (Male/Female) 168/119 53/39 0.024 0.875
Smoking history (Yes/No) 94/193 33/59 0.303 0.591
Drinking history (Yes/No) 67/220 22/70 0.012 0.911
Types of pulmonary tuberculosis Tuberculous pleurisy 21 (7.32) 1 (1.09) 11.077 0.011
Primary 32 (11.15) 3 (3.26)
Secondary 210 (73.17) 78 (84.78)
Hematogenous disseminated 24 (8.36) 10 (10.87)
Lesion scope (Unilateral/Bilateral) 132/155 29/62 5.637 0.017
Cavity formation (Yes/No) 68/219 44/48 5.564 0.018
Complicated with diabetes (Yes/No) 35/252 23/69 8.813 0.003
Complicated with hypertension (Yes/No) 56/231 20/72 0.215 0.642
Cough symptoms before treatment Severe 32 (11.15) 13 (14.13) 2.095 0.350
Moderate 138 (48.08) 49 (53.26)
Mild 117 (40.77) 30 (32.61)
Hemoptysis symptoms before treatment (Yes/No) 50/237 19/73 0.488 0.484
WBC (×10⁹/L) 6.78 ± 2.08 7.02 ± 2.31 0.937 0.349
NEUT% (%) 64.85 ± 10.12 65.23 ± 10.45 0.310 0.756
LYMPH% (%) 27.82 ± 8.25 25.15 ± 8.01 2.720 0.006
HB (g/L) 126.35 ± 15.72 123.45 ± 16.02 1.532 0.126
PLT (×10⁹/L) 213.25 ± 55.68 221.35 ± 59.42 1.194 0.233
ALB (g/L) 40.82 ± 5.15 38.95 ± 5.32 3.006 0.002
ALT (U/L) 28.15 ± 12.08 29.82 ± 12.85 1.136 0.256
AST (U/L) 27.25 ± 11.32 29.42 ± 12.15 1.571 0.116
SCr (µmol/L) 78.12 ± 15.45 79.65 ± 16.22 0.816 0.414
Sputum smear acid-fast staining (Positive/Negative) 132/155 47/45 0.725 0.394

Multivariate logistic regression analysis of influencing factors on TB treatment efficacy

Multivariate logistic regression confirmed the six factors identified by univariate analysis as independent predictors of TB treatment failure (all P < 0.05), among which TB type had the strongest predictive effect (OR = 8.930).

Using treatment efficacy as the dependent variable (effective = 1, ineffective = 0) and the six factors with statistical significance in univariate analysis as independent variables (variable assignment shown in Table 3), multivariate logistic regression analysis was performed. The results showed that all six factors were independent predictors of treatment failure (all P < 0.05) (Table 4).

Table 3.

Variable assignment methods

Variable Meaning Assignment
X1 Pulmonary tuberculosis type Tuberculous pleurisy = 0, Primary = 1, Secondary = 2, Hematogenous disseminated = 3
X2 Lesion scope Unilateral = 0, Bilateral = 1
X3 Cavity formation No = 0, Yes = 1
X4 Comorbid diabetes No = 0, Yes = 1
X5 LYMPH% Continuous variable
X6 ALB Continuous variable
Y Treatment efficacy Effective = 1, Ineffective = 0

Table 4.

Logistic regression analysis of influencing factors on the treatment efficacy of pulmonary tuberculosis patients

Indicators β SE Wald P OR 95%CI
Pulmonary tuberculosis type 2.189 0.322 46.268 0.001 8.930 4.752–16.781
Lesion scope 1.078 0.372 8.414 0.004 2.940 1.419–6.092
Cavity formation 1.345 0.141 10.529 0.001 3.836 1.703–8.642
Comorbid diabetes 1.524 0.522 8.540 0.003 4.592 1.652–12.766
LYMPH% -0.039 0.017 5.336 0.021 0.961 0.930–0.994
ALB -0.069 0.027 6.787 0.009 0.933 0.885–0.983
Constant -2.892 1.330 4.726 0.030 0.055

The odds ratios (OR) and 95% confidence intervals (CI) were as follows: TB type (OR = 8.930, 95%CI = 4.752–16.781), comorbid diabetes (OR = 4.592, 95%CI = 1.652–12.766), cavity formation (OR = 3.836, 95%CI = 1.703–8.642), lesion scope (OR = 2.940, 95%CI = 1.419–6.092), ALB level (OR = 0.933, 95%CI = 0.885–0.983), and LYMPH% (OR = 0.961, 95%CI = 0.930–0.994). The constant term was − 2.892 (P = 0.030).

Construction of a prediction model for TB treatment efficacy

Three machine learning models (RF, SVM, KNN) were constructed using the six independent predictors, with hyperparameters optimized by 5-fold cross-validation on the training set; feature importance analysis of the RF model showed lesion scope and LYMPH%/ALB had the highest contribution.

Based on the six independent predictors identified by regression analysis, data were preprocessed (format conversion and attribute definition: continuous data as numerical values, categorical data assigned 0/1) and split into 70% training and 30% test subsets. Grid search combined with 5-fold cross-validation on the training set was used to optimize model hyperparameters, and three prediction models were constructed using Random Forest (RF), Support Vector Machine (SVM), and K-Nearest Neighbors (KNN) algorithms.

Feature importance visualization of the RF model (the optimal model in subsequent evaluation) showed: lesion scope (0.060) had the highest importance, followed by LYMPH% (0.054) and ALB (0.054), then cavity formation (0.046), comorbid diabetes (0.043), and TB type (0.012).

Evaluation of the prediction model for TB treatment efficacy

Among the three models, the RF model achieved the best predictive performance (AUC = 0.783, accuracy = 81.3%, F1-score = 0.782), significantly outperforming the SVM and KNN models, and approaching the “good” predictive threshold (AUC > 0.8).

The performance of the three models was evaluated using metrics including accuracy, precision, recall, F1-score, AUC, specificity, and sensitivity (Table 5). The RF model showed the optimal performance: precision = 0.781, accuracy = 0.813, recall = 0.723, F1-score = 0.782, AUC = 0.783, specificity = 0.823, and sensitivity = 0.793.

Table 5.

Performance evaluation indicators of three machine learning models in the training set

Model Precision Accuracy Recall F1 AUC Specificity Sensitivity
Random forest model 0.781 0.813 0.723 0.782 0.783 0.823 0.793
Support vector machine model 0.702 0.783 0.762 0.703 0.707 0.826 0.714
K-nearest neighbor algorithm model 0.641 0.712 0.675 0.661 0.668 0.712 0.687

The SVM model exhibited moderate performance: precision = 0.702, accuracy = 0.783, recall = 0.762, F1-score = 0.703, AUC = 0.707, specificity = 0.826, and sensitivity = 0.714. The KNN model had the lowest performance: precision = 0.641, accuracy = 0.712, recall = 0.675, F1-score = 0.661, AUC = 0.668, specificity = 0.712, and sensitivity = 0.687. Based on AUC and F1-score, the RF model was selected as the optimal prediction model.

Discussion

In this study, univariate and multivariate logistic regression analyses identified cavitation, comorbid diabetes, bilateral lesion involvement, pulmonary TB type, LYMPH%, and ALB level as independent risk factors for treatment failure in pulmonary tuberculosis. These findings align with established research while highlighting the complex interplay of multifactorial clinical parameters on therapeutic outcomes.

Cavitation emerged as a significant predictor of treatment failure (OR = 3.836). This association is likely attributable to severe lung tissue destruction, elevated bacillary load, and compromised local drug penetration within cavities, hindering effective bactericidal activity [7, 8]. Furthermore, the cavitary environment may provide a sanctuary for Mycobacterium tuberculosis, facilitating evasion of host immune clearance. Consequently, patients with cavitary disease warrant consideration for extended treatment durations or adjunctive interventions, such as local drug delivery, to enhance lesion-specific drug concentrations [9]. Concurrently, close radiological monitoring is essential to guide timely therapeutic adjustments. Future investigations should quantify the relationship between specific imaging characteristics (e.g., cavity size, wall thickness) and treatment efficacy to refine personalized therapeutic strategies.

Comorbid diabetes substantially increased the risk of treatment failure (OR = 4.592). Impaired immune function in diabetic patients, particularly hyperglycemia-induced suppression of macrophage and T-cell activity, compromises mycobacterial clearance [10]. Additionally, diabetes may alter the pharmacokinetics of anti-tubercular drugs, potentially reducing their efficacy [11]. These results underscore the critical importance of stringent glycemic control during tuberculosis treatment. Clinical management necessitates multidisciplinary collaboration to optimize hypoglycemic regimens and monitor for potential drug-drug interactions [12]. Future research should investigate the impact of varying glycemic control targets on treatment outcomes and explore potential synergistic effects of novel hypoglycemic agents in this comorbid population.

Patients with bilateral lesion involvement exhibited a significantly higher risk of treatment failure compared to those with unilateral disease (OR = 2.940). Bilateral involvement typically signifies more extensive disease progression, higher bacillary burdens, and a more complex host immune response [13]. Widespread lesions may also exacerbate inflammatory responses and tissue damage, further impairing drug distribution and efficacy. Clinicians should maintain heightened vigilance for treatment failure in patients with bilateral disease, implementing early supportive measures such as nutritional supplementation and immune modulation, and potentially extending the intensive treatment phase [14]. Dynamic imaging assessment is particularly crucial in this subgroup, providing valuable insights for predicting therapeutic response [15]. Future studies leveraging radiomics could quantitatively assess the association between lesion extent and treatment response, enhancing predictive accuracy.

The type of pulmonary tuberculosis was a potent independent predictor of treatment outcome (OR = 8.930), with secondary pulmonary tuberculosis and hematogenous disseminated tuberculosis conferring the highest risk of failure [16, 17]. Distinct pathological mechanisms, bacillary loads, and immune responses characterize different tuberculosis types. For instance, hematogenous dissemination involves systemic spread and high bacillary loads, while secondary tuberculosis often involves immune evasion and localized tissue destruction [18]. This necessitates type-specific therapeutic approaches. For example, patients with hematogenous disseminated disease may benefit from intensified early bactericidal regimens or prolonged treatment courses. Future research should identify molecular markers associated with different tuberculosis types to underpin precise therapeutic stratification [19].

LYMPH% (OR = 0.961) and ALB level (OR = 0.933) were significantly associated with treatment failure. Reduced LYMPH% reflects compromised cellular immunity, impairing the host’s ability to eliminate M. tuberculosis. Hypoalbuminemia indicates malnutrition or inflammatory catabolism, adversely affecting drug metabolism and tissue repair [20, 21]. These biomarkers collectively emphasize the pivotal roles of immune competence and nutritional status in tuberculosis treatment success [22, 23]. Routine monitoring of lymphocyte counts and ALB levels is recommended, with prompt initiation of immune-modulating interventions (e.g., vitamin D supplementation) and nutritional support for patients exhibiting abnormalities [23]. Future studies should evaluate the feasibility of therapeutic interventions targeting LYMPH% and ALB levels (e.g., immunomodulators, high-protein diets) to improve outcomes [24].

To enhance predictive capability, we developed three machine learning models: RF, SVM, and KNN. The RF model demonstrated superior performance (AUC = 0.783, F1-score = 0.782), significantly outperforming SVM (AUC = 0.707) and KNN (AUC = 0.668). The RF’s robustness stems from its ensemble structure and random feature selection, mitigating overfitting while effectively capturing complex, non-linear interactions among clinical variables, such as the synergistic effect of cavitation and diabetes [25]. Clinically, the RF model achieved an accuracy of 81.3% and sensitivity of 79.3%, enabling the identification of over 80% of patients likely to fail treatment and nearly 80% of high-risk individuals, facilitating early intervention. Its specificity of 82.3% minimizes misclassification of low-risk patients, preventing unnecessary overtreatment. Compared to traditional logistic regression, RF offers distinct advantages for high-dimensional data analysis, autonomously identifying optimal feature combinations without reliance on researcher-defined assumptions. Feature importance analysis reinforced clinical relevance, with pulmonary tuberculosis type (weight = 0.012) and lesion scope (weight = 0.060) ranking highly, enhancing model interpretability and enabling risk-stratified management [26, 27]. For instance, patients with cavitation and diabetes warrant prioritized intensive therapy, while those with low LYMPH% and ALB may benefit from augmented immune and nutritional support, facilitating a “predict-intervene-monitor” management paradigm.

Potential clinical application value of the model

The Random Forest (RF) prediction model constructed in this study integrates six easily accessible clinical and laboratory indicators (TB type, lesion scope, cavitation, comorbid diabetes, LYMPH%, ALB), presenting notable practical value for clinical practice. First, it enables rapid risk stratification of newly diagnosed TB patients: by inputting baseline data (e.g., imaging findings, comorbidity status, routine laboratory results), clinicians can quickly identify high-risk individuals prone to treatment failure, facilitating timely adjustment of treatment strategies (e.g., extended intensive phase, nutritional or immune support). Second, the model standardizes risk assessment, reducing reliance on subjective clinical experience and improving the consistency of individualized treatment decisions. Particularly in resource-constrained settings, it can assist primary care providers in prioritizing high-risk patients for specialized management, optimizing medical resource allocation.

Limitations and future directions

Despite its promising performance, this study has inherent limitations. The single-center design and moderate sample size (n = 541) may restrict the model’s generalizability, while the lack of external validation further undermines confidence in its applicability to broader populations. Future work should prioritize expanding the cohort size, incorporating multi-center data, and including challenging subpopulations (e.g., drug-resistant TB, HIV co-infection) to enhance model universality.

Furthermore, the model only utilizes baseline parameters; integrating dynamic treatment-phase data (e.g., sputum smear conversion time, longitudinal imaging changes) via longitudinal modeling could significantly improve predictive accuracy. Relatedly, as this was a retrospective study, clinical data were collected at predefined time points rather than as continuous event logs, which precluded the construction of detailed individual event timelines to visually elucidate the dynamic progression towards treatment failure. The exclusion of molecular biomarkers (e.g., drug resistance genotypes) is another constraint, as such data may further strengthen predictive power. Additionally, limited by sample size, treatment failure was not subclassified (e.g., relapse vs. acquired resistance), which may reduce the granularity of risk stratification. Finally, the model’s clinical utility requires prospective validation—future studies should assess whether model-guided treatment decisions yield better outcomes than conventional management to confirm its practical value.

Conclusion

This study identifies key clinical and laboratory predictors of pulmonary tuberculosis treatment failure and develops a robust Random Forest model capable of predicting outcomes by integrating these multifactorial indicators. Optimizing this model through expanded datasets, inclusion of dynamic and molecular biomarkers, and prospective clinical validation holds significant promise for translating this research into a tool for personalized tuberculosis management, ultimately advancing precision medicine in this field.

Electronic Supplementary Material

Below is the link to the electronic supplementary material.

Supplementary Material 1 (20.8KB, docx)

Acknowledgements

We thank the patients and the radiology and pathology departments of Henan Chest Hospital for their support.

Author contributions

XHC, WF, WTW: Conceptualization, Methodology, Formal Analysis, Writing–Original Draft. XHC, WF, WTW and XW: Data Curation, Investigation, Software, Validation.WF, WTW, ZP and XW: Resources, Supervision, Writing–Review & Editing. WF, WTW, ZP and XW: Visualization, Project administration. All authors reviewed and approved the final manuscript.

Funding

This research received no specific grant from funding agencies in the public, commercial, or not-for-profit sectors.

Data availability

The datasets generated and analyzed during this study are available from the corresponding author upon reasonable request.

Declarations

Ethics approval and consent to participate

The Ethics Committee of Henan Provincial Chest Hospital approved this retrospective single-center study and waived informed consent received institutional review board approval [Approval No.(2024)科伦审第(05 − 01)号]. All procedures were conducted in accordance with the ethical standards of the hospital and the Declaration of Helsinki.

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.

Xiaohua Cui and Wei Fu contributed equally to this work.

References

  • 1.Nguyen BH, Dang TTH, Hoang DT, et al. An mHealth app technology to strengthen adverse event management of multi-drug-resistant tuberculosis in Vietnam: Protocol for a process evaluation of the V-SMART trial. Trop Med Int Health. 2025;30(4):273–82. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 2.Qin N, Chen J, Chen L, et al. Effectiveness of a mobile health application on treatment outcomes among patients with tuberculosis in Shanghai, China: a multicentre randomised controlled trial. BMJ Glob Health. 2025;10(6). [DOI] [PMC free article] [PubMed]
  • 3.Nijiati M, Guo L, Abulizi A, et al. Deep learning and radiomics of longitudinal CT scans for early prediction of tuberculosis treatment outcomes. Eur J Radiol. 2023;169:111180. [DOI] [PubMed] [Google Scholar]
  • 4.Canas LS, Dong THK, Beasley D, et al. Computer-aided prognosis of tuberculous meningitis combining imaging and non-imaging data. Sci Rep. 2024;14(1):17581. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 5.Wang Q, Qin X, Zhao Y, et al. Lactylation-Related Gene LILRB4 Predicts the Prognosis and Immunotherapy of Prostate Cancer Based on Machine Learning. J Cell Mol Med. 2025;29(12):e70669. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 6.Abad CLR, Razonable RR. An update on Mycobacterium tuberculosis infection after hematopoietic stem cell transplantation in adults. Clin Transpl. 2018;32(12):e13430. [DOI] [PubMed] [Google Scholar]
  • 7.Shepelkova GS, Evstifeev VV, Berezovskiy YS, et al. Characteristics of pulmonary inflammation in patients with different forms of active tuberculosis. Int J Mol Sci. 2024;25(21). [DOI] [PMC free article] [PubMed]
  • 8.Tobin EH, Gilotra TS, Baradhi KM. Aspergilloma [M]. StatPearls. Treasure Island (FL); StatPearls PublishingCopyright © 2025. StatPearls Publishing LLC; 2025.
  • 9.Kim JY, Hwang H, Yim D, et al. Relationship Between Clarithromycin Minimum Inhibitory Concentrations and Treatment Responses in Mycobacterium avium Complex Pulmonary Disease. Clin Infect Dis. 2025;80(3):637–43. [DOI] [PubMed] [Google Scholar]
  • 10.Chaubey GK, Modanwal R, Dilawari R, et al. Chronic hyperglycemia impairs anti-microbial function of macrophages in response to Mycobacterium tuberculosis infection. Immunol Res. 2024;72(4):644–53. [DOI] [PubMed] [Google Scholar]
  • 11.Xu G, Hu X, Lian Y, et al. Diabetes mellitus affects the treatment outcomes of drug-resistant tuberculosis: a systematic review and meta-analysis. BMC Infect Dis. 2023;23(1):813. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 12.Pardeshi G, Mave V, Gaikwad S, et al. Glycated Hemoglobin Trajectories and Their Association With Treatment Outcomes Among Patients With Pulmonary TB in India: A Prospective Cohort Study. Chest. 2024;165(2):278–87. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 13.Singh M, Vaid M. A Case Report of Spontaneous Subcutaneous Emphysema Secondary to Pulmonary Tuberculosis. Cureus. 2025;17(4):e82353. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 14.Li J, Yu Z, Jiang Y, et al. Rare tuberculosis in recipients of allogeneic hematopoietic stem cell transplantation successfully treated with contezolid-a typical case report and literature review. Front Cell Infect Microbiol. 2023;13:1258561. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 15.Nguyen HQ, Doan TT, Do TV, et al. Melioidosis Presenting as Chronic Pneumonia With Soft Tissue Abscess in a Diabetic Patient Initially Treated for Tuberculosis: A Case Report From Vietnam. Respirol Case Rep. 2025;13(6):e70257. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 16.Sandeyl AA, Jayte M, David MM, et al. Massive spontaneous pneumothorax with mediastinal shift in a 14-year-old with pulmonary tuberculosis: A case report. Int J Surg Case Rep. 2025;131:111422. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 17.Cummings MJ, Bakamutumaho B, Jain K, et al. Brief Report: Detection of Urine Lipoarabinomannan Is Associated With Proinflammatory Innate Immune Activation, Impaired Host Defense, and Organ Dysfunction in Adults With Severe HIV-Associated Tuberculosis in Uganda. J Acquir Immune Defic Syndr. 2023;93(1):79–85. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 18.Limkul L, Tovichien P. Secondary organizing pneumonia after infection. World J Clin Cases. 2024;12(36):6877–82. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 19.Zhang Y, Ye X, Xu J, et al. Identification and functional characterization of glycosyltransferase-related biomarkers for tuberculosis diagnosis. AMB Express. 2025;15(1):56. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 20.Harikumar Parvathy G, Hertz D, Bhandiwad D, et al. Sex differences in vaccine-induced immunity and protection against mycobacterium tuberculosis. J Infect Dis. 2025. [DOI] [PubMed]
  • 21.Luo Y, Xue Y, Song H, et al. Machine learning based on routine laboratory indicators promoting the discrimination between active tuberculosis and latent tuberculosis infection. J Infect. 2022;84(5):648–57. [DOI] [PubMed] [Google Scholar]
  • 22.Aziz A, Alshurafa A, Yassin M. Cervical Lymphadenopathy in Concomitant CML and Tuberculosis: A Case Report. Case Rep Oncol. 2025;18(1):751–5. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 23.Huang X, Zeng Y, Lin J, et al. ESAT-6 protein suppresses allograft rejection by inducing CD4(+)Foxp3(+) regulatory T cells through IκBα/cRel pathway. Front Immunol. 2024;15:1529226. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 24.Kondratyeva LG, Rakitina OA, Pleshkan VV, et al. The Cellular and Transcriptomic Early Innate Immune Response to BCG Vaccination in Mice. Cells. 2024;13:24. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 25.Alotaibi BS, Dwivedi VD, Kamal MA. Structure-based design of mycobacterium tuberculosis PptT-ACP complex inhibitors using derivative design and machine learning. Folia Microbiol (Praha). 2025. [DOI] [PubMed]
  • 26.Balobanova NP, Alymenko MA, Valiev RS, et al. Association of the Genotype of TNFα with the Efficiency of the Intensive Phase of Chemotherapy and Formation of the Sizes of Destruction Cavities in Patients with Pulmonary Tuberculosis. Bull Exp Biol Med. 2024;178(1):65–7. [DOI] [PubMed] [Google Scholar]
  • 27.Yasin P, Ding L, Mamat M, et al. Machine Learning-Based Interpretable Screening for Osteoporosis in Tuberculosis Spondylitis Patients Using Blood Test Data: Development and External Validation of a Novel Web-Based Risk Calculator with Explainable Artificial Intelligence (XAI). Infect Drug Resist. 2025;18:2797–821. [DOI] [PMC free article] [PubMed] [Google Scholar]

Associated Data

This section collects any data citations, data availability statements, or supplementary materials included in this article.

Supplementary Materials

Supplementary Material 1 (20.8KB, docx)

Data Availability Statement

The datasets generated and analyzed during this study are available from the corresponding author upon reasonable request.


Articles from BMC Infectious Diseases are provided here courtesy of BMC

RESOURCES