preprocess_functions: Examples of preprocess_fn functions

View source: R/preprocess_functions.R

preprocess_functionsR Documentation

Examples of preprocess_fn functions

Description

\Sexpr[results=rd, stage=render]{lifecycle::badge("experimental")}

Examples of preprocess functions that can be used in cross_validate_fn() and validate_fn(). They can either be used directly or be starting points.

The examples use recipes, but you can also use caret::preProcess() or similar functions.

In these examples, the preprocessing will only affect the numeric predictors.

You may prefer to hardcode a formula like "y ~ ." (where y is your dependent variable) as that will allow you to set 'preprocess_one' to TRUE in cross_validate_fn() and validate_fn() and save time.

Usage

preprocess_functions(name)

Arguments

name

Name of preprocessing function as it appears in the following list:

Name Description
"standardize" Centers and scales the numeric predictors
"range" Normalizes the numeric predictors to the 0-1 range
"scale" Scales the numeric predictors to have a standard deviation of one
"center" Centers the numeric predictors to have a mean of zero
"warn" Identity function that throws a warning and a message

Value

A function with the following form:

function(train_data, test_data, formula, hyperparameters) {

⁠ ⁠# Preprocess train_data and test_data

⁠ ⁠# Return a list with the preprocessed datasets

⁠ ⁠# and optionally a data frame with preprocessing parameters

⁠ ⁠list(

⁠ ⁠"train" = train_data,

⁠ ⁠"test" = test_data,

⁠ ⁠"parameters" = tidy_parameters

⁠ ⁠)

}

Author(s)

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

See Also

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


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