step_robust {extrasteps} | R Documentation |
Perform Robust Scaling
Description
step_robust()
creates a specification of a recipe step that will perform
Robust scaling.
Usage
step_robust(
recipe,
...,
role = NA,
trained = FALSE,
range = c(0.25, 0.75),
res = NULL,
columns = NULL,
skip = FALSE,
id = rand_id("robust")
)
Arguments
recipe |
A recipe object. The step will be added to the sequence of operations for this recipe. |
... |
One or more selector functions to choose which variables are
affected by the step. See |
role |
Not used by this step since no new variables are created. |
trained |
A logical to indicate if the quantities for preprocessing have been estimated. |
range |
A numeric vector with 2 values denoting the lower and upper
quantile that is used for scaling. Defaults to |
res |
A list containing the 3 quantiles of training variables is stored
here once this preprocessing step has be trained by |
columns |
A character string of variable names that will be populated
(eventually) by the |
skip |
A logical. Should the step be skipped when the
recipe is baked by |
id |
A character string that is unique to this step to identify it. |
Details
The scaling performed by this step is done using the following transformation
x_new = (x - Q2(x)) / (Q3(x) - Q1(x))
where Q2(x)
is the median, Q3(x)
is the upper quantile (defaults to 0.75)
and Q1(x)
is the lower quantile (defaults to 0.25). The upper and lower
quantiles can be changed with the range
argument.
Value
An updated version of recipe
with the new step added to the
sequence of existing steps (if any). For the tidy
method, a tibble with
columns terms
(the columns that will be affected) and base
.
Examples
library(recipes)
rec <- recipe(~., data = mtcars) %>%
step_robust(all_predictors()) %>%
prep()
rec %>%
bake(new_data = NULL)
tidy(rec, 1)
rec <- recipe(~., data = mtcars) %>%
step_robust(all_predictors(), range = c(0.1, 0.9)) %>%
prep()
rec %>%
bake(new_data = NULL)
tidy(rec, 1)