kfold_xval: k-fold cross-validation

View source: R/kfold_xval_class.R

kfold_xvalR Documentation

k-fold cross-validation


k-fold cross-validation is an iterative approach applied to validate models. The samples are divided into k "folds", or subsets. Each subset is excluded from model training and used for model validation once, resulting in a single left-out prediction for each sample. Model performance metrics are then computed for the training and test sets across all folds.


kfold_xval(folds = 10, method = "venetian", factor_name, collect = NULL, ...)



(numeric, integer) The number of cross-validation folds. The default is 10.


(character) Fold selection method. Allowed values are limited to the following:

  • "venetian": Every nth sample is assigned to the same fold, where n is the number of folds.

  • "blocks": Blocks of adjacent samples are assigned to the same fold.

  • "random": Samples are randomly assigned to a fold.

The default is "venetian".


(character) The name of a sample-meta column to use.


(NULL, character) The name of a model output to collect over all bootstrap repetitions, in addition to the input metric. The default is NULL.


Additional slots and values passed to struct_class.


A kfold_xval object with the following output slots:

results (data.frame)
metric (data.frame)
metric.train (numeric)
metric.test (numeric)
collected (list)


D = iris_DatasetExperiment()
I = kfold_xval(factor_name='Species') *
    (mean_centre() + PLSDA(factor_name='Species'))
I = run(I,D,balanced_accuracy())

computational-metabolomics/structToolbox documentation built on Feb. 6, 2023, 2:43 p.m.