Abstract
Background: Machine learning (ML) applied to lung and gut microbiota offers substantial yet underexplored potential for improving tuberculosis (TB) diagnosis and prognosis. Progress has been limited by insufficiently large and standardised datasets. Here, we applied ML models to globally curated microbiota datasets to classify TB cases and healthy controls.Methods: Datasets are from our recently published systematic review of 42 studies (2010–2024) reporting microbiota changes associated with TB. The harmonised lung and gut datasets include n=1,617 participants. Six ML model types were optimised across 36 parameters for diagnostic (TB status) and prognostic (treatment status) classification. Models were trained, cross-validated, and independently validated using 70%, 20%, and 10% of each dataset, respectively.Findings: The dataset included 1,181 lung and 550 gut microbiota samples, of which 1,264 (73%) were microbiologically confirmed TB cases; 89% of samples originated from Africa and Asia. In the global lung dataset, Lasso II and Ridge II models achieved an area under the receiver operating characteristic curve (AUROC) of 0.93 and 0.92 during cross-validation and correctly classified 64 of 75 TB cases. External independent validation (n=94) showed comparable performance, correctly classifying 63 of 75 cases. Although Africa- and Asia-specific models performed similarly to global models during cross-validation, their performance did not generalise to external validation. Random Forest models performed best on treatment-phase lung samples and on gut microbiota datasets, achieving cross-validation metrics comparable to those from the lung analyses. Genera such as Rothia, Gemella, Prevotella, and Streptococcus consistently ranked among the strongest predictors of pulmonary TB, suggesting potential biomarker value.Interpretation: ML models leveraging lung and gut microbiota show promise as complementary tools for TB diagnosis, particularly for extrapulmonary or hard-to-diagnose cases. This work provides a foundation for clinical metagenomics in TB diagnostics and prognostics. To support reproducibility and future innovation, we release MLTBdx, an open-source pipeline and dataset.