Skip to contents

Selects the model configuration (learning rate, optimizer, epochs, L2) minimising / maximising a resampled metric.

Usage

morie_ml_tune(
  x,
  y,
  grid,
  type = "linear",
  n_folds = 5L,
  metric = if (type == "logistic") "roc_auc" else "rmse",
  maximize = metric %in% c("roc_auc", "accuracy", "r2"),
  seed = 42L
)

Arguments

x

Predictors.

y

Response.

grid

A data.frame whose columns are morie_ml_model arguments; each row is a candidate configuration.

type

"logistic" or "linear".

n_folds

Resampling folds.

metric

Metric to optimise.

maximize

Whether larger metric is better (default: TRUE for roc_auc/accuracy/r2, FALSE otherwise).

seed

RNG seed.

Value

A list with the full results table and the best row.

Examples

g <- expand.grid(learning_rate = c(0.01, 0.1), optimizer = "gd",
                 stringsAsFactors = FALSE)
morie_ml_tune(mtcars[c("hp", "wt")], mtcars$mpg, g,
              type = "linear", n_folds = 3)$best
#>   learning_rate optimizer    score
#> 1          0.01        gd 2.767045