Fork me on GitHub

classify-samples: Train and test a cross-validated supervised learning classifier.ΒΆ

Docstring:

Usage: qiime sample-classifier classify-samples [OPTIONS]

  Predicts a categorical sample metadata column using a supervised learning
  classifier. Splits input data into training and test sets. The training set
  is used to train and test the estimator using a stratified k-fold cross-
  validation scheme. This includes optional steps for automated feature
  extraction and hyperparameter optimization. The test set validates
  classification accuracy of the optimized estimator. Outputs classification
  results for test set. For more details on the learning algorithm, see
  http://scikit-learn.org/stable/supervised_learning.html

Inputs:
  --i-table ARTIFACT FeatureTable[Frequency | RelativeFrequency |
    PresenceAbsence | Composition]
                          Feature table containing all features that should
                          be used for target prediction.            [required]
Parameters:
  --m-metadata-file METADATA
  --m-metadata-column COLUMN  MetadataColumn[Categorical]
                          Categorical metadata column to use as prediction
                          target.                                   [required]
  --p-test-size PROPORTION
    Range(0.0, 1.0)       Fraction of input samples to exclude from training
                          set and use for classifier testing.   [default: 0.2]
  --p-step PROPORTION Range(0.0, 1.0, inclusive_start=False)
                          If optimize-feature-selection is True, step is the
                          percentage of features to remove at each iteration.
                                                               [default: 0.05]
  --p-cv INTEGER          Number of k-fold cross-validations to perform.
    Range(1, None)                                                [default: 5]
  --p-random-state INTEGER
                          Seed used by random number generator.     [optional]
  --p-n-jobs NTHREADS     Number of jobs to run in parallel.      [default: 1]
  --p-n-estimators INTEGER
    Range(1, None)        Number of trees to grow for estimation. More trees
                          will improve predictive accuracy up to a threshold
                          level, but will also increase time and memory
                          requirements. This parameter only affects ensemble
                          estimators, such as Random Forest, AdaBoost,
                          ExtraTrees, and GradientBoosting.     [default: 100]
  --p-estimator TEXT Choices('RandomForestClassifier',
    'ExtraTreesClassifier', 'GradientBoostingClassifier',
    'AdaBoostClassifier[DecisionTree]', 'AdaBoostClassifier[ExtraTrees]',
    'KNeighborsClassifier', 'LinearSVC', 'SVC')
                          Estimator method to use for sample prediction.
                                           [default: 'RandomForestClassifier']
  --p-optimize-feature-selection / --p-no-optimize-feature-selection
                          Automatically optimize input feature selection
                          using recursive feature elimination.
                                                              [default: False]
  --p-parameter-tuning / --p-no-parameter-tuning
                          Automatically tune hyperparameters using random
                          grid search.                        [default: False]
  --p-palette TEXT Choices('YellowOrangeBrown', 'YellowOrangeRed',
    'OrangeRed', 'PurpleRed', 'RedPurple', 'BluePurple', 'GreenBlue',
    'PurpleBlue', 'YellowGreen', 'summer', 'copper', 'viridis', 'cividis',
    'plasma', 'inferno', 'magma', 'sirocco', 'drifting', 'melancholy',
    'enigma', 'eros', 'spectre', 'ambition', 'mysteriousstains', 'daydream',
    'solano', 'navarro', 'dandelions', 'deepblue', 'verve', 'greyscale')
                          The color palette to use for plotting.
                                                          [default: 'sirocco']
  --p-missing-samples TEXT Choices('error', 'ignore')
                          How to handle missing samples in metadata. "error"
                          will fail if missing samples are detected. "ignore"
                          will cause the feature table and metadata to be
                          filtered, so that only samples found in both files
                          are retained.                     [default: 'error']
Outputs:
  --o-sample-estimator ARTIFACT SampleEstimator[Classifier]
                          Trained sample estimator.                 [required]
  --o-feature-importance ARTIFACT FeatureData[Importance]
                          Importance of each input feature to model accuracy.
                                                                    [required]
  --o-predictions ARTIFACT SampleData[ClassifierPredictions]
                          Predicted target values for each input sample.
                                                                    [required]
  --o-model-summary VISUALIZATION
                          Summarized parameter and (if enabled) feature
                          selection information for the trained estimator.
                                                                    [required]
  --o-accuracy-results VISUALIZATION
                          Accuracy results visualization.           [required]
  --o-probabilities ARTIFACT SampleData[Probabilities]
                          Predicted class probabilities for each input
                          sample.                                   [required]
  --o-heatmap VISUALIZATION
                          A heatmap of the top 50 most important features
                          from the table.                           [required]
  --o-training-targets ARTIFACT SampleData[TrueTargets]
                          Series containing true target values of train
                          samples                                   [required]
  --o-test-targets ARTIFACT SampleData[TrueTargets]
                          Series containing true target values of test
                          samples                                   [required]
Miscellaneous:
  --output-dir PATH       Output unspecified results to a directory
  --verbose / --quiet     Display verbose output to stdout and/or stderr
                          during execution of this action. Or silence output
                          if execution is successful (silence is golden).
  --recycle-pool TEXT     Use a cache pool for pipeline resumption. QIIME 2
                          will cache your results in this pool for reuse by
                          future invocations. These pool are retained until
                          deleted by the user. If not provided, QIIME 2 will
                          create a pool which is automatically reused by
                          invocations of the same action and removed if the
                          action is successful. Note: these pools are local to
                          the cache you are using.
  --no-recycle            Do not recycle results from a previous failed
                          pipeline run or save the results from this run for
                          future recycling.
  --parallel              Execute your action in parallel. This flag will use
                          your default parallel config.
  --parallel-config FILE  Execute your action in parallel using a config at
                          the indicated path.
  --use-cache DIRECTORY   Specify the cache to be used for the intermediate
                          work of this pipeline. If not provided, the default
                          cache under $TMP/qiime2/ will be used.
                          IMPORTANT FOR HPC USERS: If you are on an HPC system
                          and are using parallel execution it is important to
                          set this to a location that is globally accessible
                          to all nodes in the cluster.
  --example-data PATH     Write example data and exit.
  --citations             Show citations and exit.
  --help                  Show this message and exit.

Import:

from qiime2.plugins.sample_classifier.pipelines import classify_samples

Docstring:

Train and test a cross-validated supervised learning classifier.

Predicts a categorical sample metadata column using a supervised learning
classifier. Splits input data into training and test sets. The training set
is used to train and test the estimator using a stratified k-fold cross-
validation scheme. This includes optional steps for automated feature
extraction and hyperparameter optimization. The test set validates
classification accuracy of the optimized estimator. Outputs classification
results for test set. For more details on the learning algorithm, see
http://scikit-learn.org/stable/supervised_learning.html

Parameters
----------
table : FeatureTable[Frequency | RelativeFrequency | PresenceAbsence | Composition]
    Feature table containing all features that should be used for target
    prediction.
metadata : MetadataColumn[Categorical]
    Categorical metadata column to use as prediction target.
test_size : Float % Range(0.0, 1.0), optional
    Fraction of input samples to exclude from training set and use for
    classifier testing.
step : Float % Range(0.0, 1.0, inclusive_start=False), optional
    If optimize_feature_selection is True, step is the percentage of
    features to remove at each iteration.
cv : Int % Range(1, None), optional
    Number of k-fold cross-validations to perform.
random_state : Int, optional
    Seed used by random number generator.
n_jobs : Threads, optional
    Number of jobs to run in parallel.
n_estimators : Int % Range(1, None), optional
    Number of trees to grow for estimation. More trees will improve
    predictive accuracy up to a threshold level, but will also increase
    time and memory requirements. This parameter only affects ensemble
    estimators, such as Random Forest, AdaBoost, ExtraTrees, and
    GradientBoosting.
estimator : Str % Choices('RandomForestClassifier', 'ExtraTreesClassifier', 'GradientBoostingClassifier', 'AdaBoostClassifier[DecisionTree]', 'AdaBoostClassifier[ExtraTrees]', 'KNeighborsClassifier', 'LinearSVC', 'SVC'), optional
    Estimator method to use for sample prediction.
optimize_feature_selection : Bool, optional
    Automatically optimize input feature selection using recursive feature
    elimination.
parameter_tuning : Bool, optional
    Automatically tune hyperparameters using random grid search.
palette : Str % Choices('YellowOrangeBrown', 'YellowOrangeRed', 'OrangeRed', 'PurpleRed', 'RedPurple', 'BluePurple', 'GreenBlue', 'PurpleBlue', 'YellowGreen', 'summer', 'copper', 'viridis', 'cividis', 'plasma', 'inferno', 'magma', 'sirocco', 'drifting', 'melancholy', 'enigma', 'eros', 'spectre', 'ambition', 'mysteriousstains', 'daydream', 'solano', 'navarro', 'dandelions', 'deepblue', 'verve', 'greyscale'), optional
    The color palette to use for plotting.
missing_samples : Str % Choices('error', 'ignore'), optional
    How to handle missing samples in metadata. "error" will fail if missing
    samples are detected. "ignore" will cause the feature table and
    metadata to be filtered, so that only samples found in both files are
    retained.

Returns
-------
sample_estimator : SampleEstimator[Classifier]
    Trained sample estimator.
feature_importance : FeatureData[Importance]
    Importance of each input feature to model accuracy.
predictions : SampleData[ClassifierPredictions]
    Predicted target values for each input sample.
model_summary : Visualization
    Summarized parameter and (if enabled) feature selection information for
    the trained estimator.
accuracy_results : Visualization
    Accuracy results visualization.
probabilities : SampleData[Probabilities]
    Predicted class probabilities for each input sample.
heatmap : Visualization
    A heatmap of the top 50 most important features from the table.
training_targets : SampleData[TrueTargets]
    Series containing true target values of train samples
test_targets : SampleData[TrueTargets]
    Series containing true target values of test samples