step_pls {recipes} | R Documentation |
step_pls
creates a specification of a recipe step that will
convert numeric data into one or more new dimensions.
step_pls(recipe, ..., role = "predictor", trained = FALSE, num_comp = 2, outcome = NULL, options = NULL, res = NULL, num = NULL, prefix = "PLS", skip = FALSE, id = rand_id("pls")) ## S3 method for class 'step_pls' tidy(x, ...)
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 will be used to compute the dimensions. See
|
role |
For model terms created by this step, what analysis role should they be assigned?. By default, the function assumes that the new dimension columns created by the original variables will be used as predictors in a model. |
trained |
A logical to indicate if the quantities for preprocessing have been estimated. |
num_comp |
The number of pls dimensions to retain as new
predictors. If |
outcome |
When a single outcome is available, character
string or call to |
options |
A list of options to |
res |
The |
num |
The number of components to retain (this will be
deprecated in factor of |
prefix |
A character string that will be the prefix to the resulting new variables. See notes below. |
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. |
x |
A |
PLS is a supervised version of principal component analysis that requires one or more numeric outcomes to compute the new features. The data should be scaled (and perhaps centered) prior to running these calculations.
This step requires the pls package. If not installed, the step will stop with a note about installing the package.
The argument num_comp
controls the number of components that will
be retained (the original variables that are used to derive the
components are removed from the data). The new components will
have names that begin with prefix
and a sequence of numbers.
The variable names are padded with zeros. For example, if num_comp < 10
, their names will be PLS1
- PLS9
. If num_comp = 101
, the
names would be PLS001
- PLS101
.
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
selectors or variables selected).
step_pca()
step_kpca()
step_ica()
recipe()
prep.recipe()
bake.recipe()
data(biomass) biomass_tr <- biomass[biomass$dataset == "Training",] biomass_te <- biomass[biomass$dataset == "Testing",] pls_rec <- recipe(HHV ~ ., data = biomass_tr) %>% step_rm(sample, dataset) %>% step_center(all_predictors()) %>% step_scale(all_predictors()) %>% # If the outcome(s) need standardization, do it in separate # steps with skip = FALSE so that new data where the # outcome is missing can be processed. step_center(all_outcomes(), skip = TRUE) %>% step_scale(all_outcomes(), skip = TRUE) %>% step_pls(all_predictors(), outcome = "HHV") pls_rec <- prep(pls_rec, training = biomass_tr, retain = TRUE) pls_test_scores <- bake(pls_rec, new_data = biomass_te[, -8]) tidy(pls_rec, number = 6)