Skip to contents

Returns a learner that, whenever it is fitted, searches grid on the units it is handed and fits the setting that scored best. The search is a cross-validation inside those units, so in a run the outer folds never see it: each fold chooses from its own training units, and the score it is then read at is not selected on. biomod2's BIOMOD_Tuning() searches a grid per algorithm by the same device.

Usage

tune(learner, grid = NULL, metric = NULL, n_inner = 5L, seed = 1L)

Arguments

learner

A learner(), or the name of a registered one.

grid

A named list of values to try, one element per setting, or NULL for the grid registered for the learner.

metric

The registered metric, or a function of (y, p), a setting is scored by. Left unset it is the response head's own.

n_inner

Number of inner folds.

seed

Random seed of the inner folds.

Value

A learner() reporting under the name of the one it wraps.

Details

A learner's settings are the ones it carries as params: the arguments of its constructor, as mtry and trees are for forest(). grid names some of them and gives the values to try; the grid is every combination. A value that is itself a vector, as the layer widths of mlp() are, is given as an element of a list. The inner folds are dealt by fold_map() and keep the grouping the outer fold map keeps whole. A setting is scored by the mean over the responses of the mean over inner folds of metric on the cells a score is defined on, and ties go to the first combination in the grid.

What was chosen is recorded: on the fitted model as $model$chosen and $model$table, and in the settings column of the candidate table of a run, which reads the model fitted on all targets.

With grid left unset the learner is searched over the grid registered under its name by register_tuning(), which for the learners that ship is the one BIOMOD_Tuning() searches: mtry of a forest() from 1 to the smaller of 10 and the number of columns; trees, depth and shrinkage of a gbm-style boosting(), shrinkage and colsample of the second-order one; degree and nprune of mars(); degree of discriminant(); regmult of maxent(); quantile of envelope(); hidden of a perceptron() at 2, 4, 6 and 8 with decay at 0.01, 0.05 and 0.1; and the layer width of mlp() at 2, 4, 6 and 8.

Examples

tuned <- tune(forest(), list(mtry = c(2, 4), min_node = c(1, 5)), n_inner = 3L)
tuned