Learn R Programming

recipes (version 0.1.7)

step_pls: Partial Least Squares Feature Extraction

Description

step_pls creates a specification of a recipe step that will convert numeric data into one or more new dimensions.

Usage

step_pls(recipe, ..., role = "predictor", trained = FALSE,
  num_comp = 2, outcome = NULL, options = NULL, res = NULL,
  prefix = "PLS", skip = FALSE, id = rand_id("pls"))

# S3 method for step_pls tidy(x, ...)

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 will be used to compute the dimensions. See selections() for more details. For the tidy method, these are not currently used.

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 num_comp is greater than the number of columns or the number of possible dimensions, a smaller value will be used.

outcome

When a single outcome is available, character string or call to dplyr::vars() can be used to specify the variable. When there are multipole outcomes, dplyr::vars() must be used. This that can include specific variable names separated by commas or different selectors (see selections()).

options

A list of options to pls::plsr().

res

The pls::plsr() object is stored here once this preprocessing step has be trained by prep.recipe().

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 bake.recipe()? While all operations are baked when prep.recipe() is run, some operations may not be able to be conducted on new data (e.g. processing the outcome variable(s)). Care should be taken when using skip = TRUE as it may affect the computations for subsequent operations

id

A character string that is unique to this step to identify it.

x

A step_pls object

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 selectors or variables selected).

Details

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.

See Also

step_pca() step_kpca() step_ica() recipe() prep.recipe() bake.recipe()

Examples

Run this code
# NOT RUN {
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_normalize(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_normalize(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 = 4)
# }

Run the code above in your browser using DataLab