auto_simon_ml: Automated Machine Learning Model Building

View source: R/functions.R

auto_simon_mlR Documentation

Automated Machine Learning Model Building

Description

This function automates the process of building machine learning models using the caret package. It supports both binary and multi-class classification and allows users to specify a list of machine learning algorithms to be trained on the dataset.

Usage

auto_simon_ml(dataset_ml, settings)

Arguments

dataset_ml

A data frame containing the dataset for training. All columns except the outcome column (and any specified in settings$excludedColumns) should contain the features.

settings

A list containing the following parameters:

  • outcome: A string specifying the name of the outcome column in dataset_ml. Defaults to "immunaut".

  • models or selectedPackages: A character vector specifying the machine learning algorithms to train (e.g., "rpart", "rf"). Defaults to c("nb", "rpart").

  • trainTestRatio or selectedPartitionSplit: A numeric value specifying the proportion of data for training (between 0 and 1). Defaults to 0.7.

  • excludedColumns: A character vector of column names to be excluded from feature predictors. Defaults to NULL.

  • preProcessDataset: A character vector of preprocessing transformations (e.g., c("medianImpute", "center", "scale", "zv")). Defaults to NULL.

  • num_cores: Integer. The number of CPU cores to use for parallel training. Defaults to 2 (or 1 during CRAN check environments).

  • kFold: Integer. The number of cross-validation folds. Defaults to 5.

  • kFoldRepeat: Integer. The number of cross-validation repeats. Defaults to 1.

  • trainingTimeout: Numeric. Timeout in seconds for training each individual model. Defaults to 180.

Details

To prevent data leakage, the dataset is partitioned into training and testing sets before any preprocessing is performed. Transformation parameters (imputation, centering, scaling, filtering) are learned exclusively from the training partition and applied without leakage to the test set.

The function partitions the data into training and testing sets prior to applying preprocessing, guaranteeing strict isolation between train and test distributions. Models are trained using repeated cross-validation via caret::train().

For binary classification, AUROC and PR-AUC are calculated. For multi-class classification, macro-averaged AUROC, weighted AUROC, and macro-averaged F1 scores are computed from the test partition.

Value

A list containing:

  • models: A list where each element corresponds to a trained model. Contains info, training, and predictions.

  • dataset: The combined preprocessed dataset.

  • trainData: The preprocessed training dataset.

  • testData: The preprocessed test dataset.

  • is_binary_classification: Logical indicating whether the problem is binary classification.

  • preProcessParams: The preprocessing parameter object(s) fitted on the training dataset.

Examples


# Generate demo dataset and run clustering pipeline
demo_data <- generate_demo_data(n_subjects = 80, n_features = 8, desired_number_clusters = 3)
settings <- list(preProcessDataset = c("medianImpute", "center", "scale"))
result <- immunaut(demo_data, settings)

# Train automated machine learning model on clustered cohort
ml_settings <- list(
    outcome = "immunaut",
    models = c("rpart"),
    excludedColumns = c("outcome", "age", "gender"),
    preProcessDataset = c("medianImpute", "center", "scale"),
    trainTestRatio = 0.7,
    num_cores = 1
)
ml_results <- auto_simon_ml(result$dataset$dataset_ml, ml_settings)
print(names(ml_results$models))



immunaut documentation built on Sept. 10, 2026, 5:09 p.m.