update_hyperparameters: Check and update hyperparameters

View source: R/update_hyperparameters.R

update_hyperparametersR Documentation

Check and update hyperparameters

Description

\Sexpr[results=rd, stage=render]{lifecycle::badge("experimental")}
  1. Checks if the required hyperparameters are present and throws an error when it is not the case.

  2. Inserts the missing hyperparameters with the supplied default values.

For managing hyperparameters in custom model functions for cross_validate_fn() or validate_fn().

Usage

update_hyperparameters(..., hyperparameters, .required = NULL)

Arguments

...

Default values for missing hyperparameters.

E.g.:

kernel = "linear", cost = 10

hyperparameters

list of hyperparameters as supplied to cross_validate_fn(). Can also be a single-row data.frame.

.required

Names of required hyperparameters. If any of these are not present in the hyperparameters, an error is thrown.

Value

A named list with the updated hyperparameters.

Author(s)

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

See Also

Other example functions: model_functions(), predict_functions(), preprocess_functions()

Examples


# Attach packages
library(cvms)

# Create a list of hyperparameters
hparams <- list(
  "kernel" = "radial",
  "scale" = TRUE
)

# Update hyperparameters with defaults
# Only 'cost' is changed as it's missing
update_hyperparameters(
  cost = 10,
  kernel = "linear",
  "scale" = FALSE,
  hyperparameters = hparams
)

# 'cost' is required
# throws error
if (requireNamespace("xpectr", quietly = TRUE)){
  xpectr::capture_side_effects(
    update_hyperparameters(
      kernel = "linear",
      "scale" = FALSE,
      hyperparameters = hparams,
      .required = "cost"
    )
  )
}



cvms documentation built on Sept. 11, 2024, 6:22 p.m.