Choose between ML Regression or Classification
From the module panel, choose either the ML Regression or the ML Classification module, depending on the type of output your model will predict. The question to ask is: “Is the outcome I want to predict categorical or numerical?”ML Regression
Predicts a numerical value: how much?For example, a metabolite concentration, an inflammation marker, a clinical score, or the age of a patient.
ML Classification
Predicts a category: which group?For example, patient vs healthy control, responder vs non-responder, or one of several body sites.
Choose what your model should predict
Select the variable your model should predict through the Target Variable parameter in the Analysis section. It lists the metadata columns available for your dataset: categorical for classification, numerical for regressionTraining an ML model
Building a model requires a set of samples for which both parts are available: the Input data (microbial, metabolomic, or functional profiles) and the target Variable we want to predict (a label for classification, or a value for regression). The phase where complete data is used to ‘teach’ a model what are the data patterns that allow to link input data to make a prediction of a target variable is called model training. During model training, the model learns the input-to-output relationship between your data and the output. For this reason, training requires a dataset where, for each sample, both the data used for prediction and the outcome to predict are available (Training dataset).Pre-processing the Data Table
As in any other analysis module on Cosmos-Hub 2.0, the input to the ML model is the Cohort Data Table that was assembled at creation of the Analysis Project through the Query Builder. Pre-processing parameters directly affect the microbial features table used for the analyses modules. In ML, particular care is needed when choosing pre-processing parameters, since this will decide many aspects of the input table used for training.Overfitting, noise, and the imbalance between the number of features and samples strongly affect how well an ML model trains and generalizes, and pre-processing is where you most influence them. Filtering too aggressively removes real low-abundance or condition-specific signal, so reduce features and samples only as far as the noise and overfitting warrant.
Choose the ML algorithm
The ML algorithm is the method the model uses to find the patterns that link the input data to the target. Different algorithms learn different kinds of relationships between microbiome features and the target variable. Choose it from the ML Algorithm parameter dropdown.
More flexible algorithms, like Support Vector Machines, can capture more complex patterns but at cost of harder interpretability; simpler ones, like linear and logistic regression, are less powerful but output offer easier to interpret, which makes them ideal to understand which features and how much are associated with the target variable.
Correct for confounding variables (Covariates)
A confounding variable, or confounder, is a factor associated with both the input and the target, which can create or mask an apparent link between them. The microbiome is shaped by many such factors, including age, sex, BMI, diet, and health conditions. When one of these factors differs systematically between your groups, the model can pick up its effect and mistake it for a microbiome-target relationship. Covariates are the factors you adjust for to prevent this: variables you expect to influence the microbiome but that are not the biological signal you want to study. Use the Covariates parameter dropdown in the Analysis section to select the categorical or numerical metadata variables to correct for.Confounders in microbiome studiesFor example, if you train a model to predict a disease from the gut microbiome but the patients are older on average than the controls, the model may partly learn age-related shifts in the microbiome and appear to predict the disease when it is in part reading age. Adjusting for age (and other host factors) as covariates or through matching has been shown to markedly reduce spurious microbiome–disease signals.Vujkovic-Cvijin I et al. Host variables confound gut microbiota studies of human disease. Nature. 2020;587:448–454.
Evaluate and optimize the model with Cross-Validation (K-fold)
Training a model raises two problems:- Overfitting. The model may fit patterns specific to the training data, such as batch effects or noise, rather than real biology. It then performs well on the samples it was trained on but poorly on new ones.
- Hyperparameter selection. ML algorithms have hyperparameters, settings that are not learned from the data and must be chosen.
K parts, called folds. The model is trained on most folds and tested on the held-out fold. This is repeated until each fold has been used as the test set once.
For example, with 5 folds, the model trains on four-fifths of the data and tests on the remaining fifth, repeating this process five times.
For most microbiome datasets, 5 folds is a good default. Use more folds only when the dataset is large enough to support stable splits. For classification, be especially careful when some classes are small: each fold needs enough samples from each class to make the evaluation meaningful.
Run the model and read the results
Once the parameters are set, click Apply and Run. The model will be trained on your data and then display the results of the module described in the next two sections. The next sections cover how to interpret the output of the ML Classification and ML Regression modules, evaluate the performances of the ML model and explore which are the microbial features (e.g: taxa, functions) that appear to be behind the biological patterns.Recommended parameters
Pre-processing
- Kepler - Host-Agnostic Taxonomic Profiling (WGS)
- CHAMP - Human Taxonomic Profiling (WGS)
- Short-read 16S - Taxonomic
- 16S LR Amplicon profiling - Taxonomic
- Host-Agnostic Functional
- CHAMP Functional (GMM, GBM, KEGG)
- AMR/VF - Functional
Model settings
Parameter reference
ML Algorithm
ML Algorithm
The machine-learning algorithm used to predict the target from microbiome features.Options ·
- ML Regression:
Random Forest,Linear Regression,ElasticNet Regression,Gradient Boosting Regressor,Support Vector Machine Regressor - ML Classification:
Random Forest,Logistic Regression,ElasticNet Logistic Regression,Gradient Boosting,Support Vector Machine.
Random ForestDifferent algorithms capture different relationships: some are easier to interpret, others predict more accurately.
Random Forest is a strong general-purpose default.Target Variable
Target Variable
The variable the ML model should predict: the biological or clinical measurement you want to estimate from microbiome data.Options · One metadata column from those attached to the samples in the cohort. The required type (numerical or categorical) depends on the module:
- ML Regression: numerical metadata (for example
metabolite_concentration,age,bmi). - ML Classification: categorical metadata, with two or more classes (for example
sex,health_status,disease_severity,sample_source).
NoneSuggested · The variable behind your scientific question, the one you want to predict from the microbiome. For exploration or hypothesis generation, testing how well the microbiome predicts a given target is a good way to find out whether that variable could drive differences in microbiome.Drop samples with missing target
Drop samples with missing target
Whether samples with a missing target value are excluded.
- **Options **
TRUEorFALSE - Default ·
TRUE
Covariates
Covariates
Numeric or binary metadata variables to correct for potential confounding before training.Options · Numeric or binary metadata columns from the metadata table associated with the queryDefault ·
NoneSuggested · Variables that may confound the relationship with the target and have a plausible linear effect on features (for example age, BMI, sex).Example: If age is associated with both composition and the target, including it as a covariate helps separate microbiome-related signal from age-related effects.
Drop samples with missing covariates
Drop samples with missing covariates
Whether samples with missing covariate values are excluded. Available only when one or more covariates are selected.Options ·
TRUE or FALSEDefault · TRUESuggested · TRUE when covariate values are required for Covariates adjustment.Top Features (N)
Top Features (N)
The number of top-ranked features shown from the best-performing model: the taxa or functions that contributed most to predicting the target.Options · Integer from
1 to 30Default · 10Feature Metric
Feature Metric
Whether the model uses features as relative abundance or presence/absence. This defines the biological signal the model learns from.Options ·
abundance, presenceDefault · abundanceNumber of K-folds
Number of K-folds
The number of folds in stratified k-fold cross-validation. The data is split into this many parts (each preserving the target’s class distribution), and each is used once as the test set.
- Options: Integer from
2to20 - Default:
5