step_sbf | R Documentation |
Creates a specification of a recipe step that will select variables from a candidate set according to a user-specified filtering function.
step_sbf(
recipe,
...,
filter,
multivariate = FALSE,
options = list(),
replace = TRUE,
prefix = "SBF",
role = "predictor",
skip = FALSE,
id = recipes::rand_id("sbf")
)
## S3 method for class 'step_sbf'
tidy(x, ...)
recipe |
recipe object to which the step will be added. |
... |
one or more selector functions to choose which variables will be
used to compute the components. See |
filter |
function whose first argument |
multivariate |
logical indicating that candidate variables be passed to
the |
options |
list of elements to be added to the step object for use in the
|
replace |
logical indicating whether to replace the original variables. |
prefix |
if the original variables are not replaced, the selected variables are added to the dataset with the character string prefix added to their names; otherwise, the original variable names are retained. |
role |
analysis role that added step variables should be assigned. By default, they are designated as model predictors. |
skip |
logical indicating whether to skip the step when the recipe is
baked. While all operations are baked when |
id |
unique character string to identify the step. |
x |
|
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
(selectors or variables selected), selected
(logical indicator of selected variables), and name
of the selected
variable names.
recipe
, prep
,
bake
library(recipes)
glm_filter <- function(x, y, step) {
model_fit <- glm(y ~ ., data = data.frame(y, x))
p_value <- drop1(model_fit, test = "F")[-1, "Pr(>F)"]
p_value < step$threshold
}
rec <- recipe(rating ~ ., data = attitude)
sbf_rec <- rec %>%
step_sbf(all_numeric_predictors(),
filter = glm_filter, options = list(threshold = 0.05))
sbf_prep <- prep(sbf_rec, training = attitude)
sbf_data <- bake(sbf_prep, attitude)
pairs(sbf_data, lower.panel = NULL)
tidy(sbf_rec, number = 1)
tidy(sbf_prep, number = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.