View source: R/wavelength_selection.R
| step_select_wavelengths | R Documentation |
step_select_wavelengths() creates a specification of a recipe step
that keeps the predictors (wavelengths) selected by
select_wavelengths() and removes the others. The selection is made on
the training data when the recipe is prepped, so that within
tune::tune_grid() it is repeated on the analysis set of every
resample, as it must be: a selection made on all the data would make the
cross-validated error too optimistic.
step_select_wavelengths(
recipe,
...,
role = NA,
trained = FALSE,
outcome = NULL,
method = "vip",
num_terms = NULL,
threshold = NULL,
num_comp = 5,
recursive = FALSE,
intervals = 40,
num_intervals = NULL,
robust = FALSE,
options = list(),
res = NULL,
columns = NULL,
skip = FALSE,
id = recipes::rand_id("select_wavelengths")
)
recipe |
A recipe object. The step will be added to the sequence of operations for this recipe. |
... |
One or more selector functions to choose the predictors (for
example, the spectral channels). See |
role |
Not used by this step, since no new variables are created. |
trained |
A logical indicating whether the step has been trained. |
outcome |
The outcome variable, as a bare name or a selector. If
|
method |
The OSC algorithm: |
num_terms |
The number of variables to keep ( |
threshold |
The importance above which variables are kept when
|
num_comp |
The number of components of the selection model ( |
recursive |
If |
intervals |
The number of contiguous intervals ( |
num_intervals |
The number of intervals to select ( |
robust |
If |
options |
A list of further arguments of |
res |
The selection, stored once the step has been trained. |
columns |
The names of the selected predictors, stored once the step has been trained. |
skip |
A logical. Should the step be skipped when the recipe is baked
by |
id |
A character string that is unique to this step. |
See select_wavelengths() for the methods: "vip" and "sr" keep the
num_terms most important predictors (or those above threshold), and
"ipls" selects num_intervals contiguous intervals. The outcome is not
needed when new data are baked.
An updated version of recipe with the new step added to the
sequence of existing steps.
num_terms, num_intervals and num_comp (the components of the
selection model) can be tuned with tune::tune(). Their default ranges
are dials::num_terms() with 20 to 1000 predictors, num_intervals()
with 1 to 10 intervals, and dials::num_comp() with 1 to 10 components.
When the model also has a num_comp argument, give the step's parameter
its own id, such as num_comp = tune("select_comp").
tidy() returns a tibble with columns terms (the
selected predictors), selected, importance and id.
Christian L. Goueguel
select_wavelengths(), plot_wavelength_selection()
library(recipes)
data(forageLIBS)
wl <- suppressWarnings(as.numeric(names(forageLIBS)))
dat <- forageLIBS[c(which(names(forageLIBS) == "Ca"), which(wl > 380 & wl < 430))]
rec <- recipe(Ca ~ ., data = dat[1:300, ]) |>
step_select_wavelengths(all_predictors(), method = "sr", num_terms = 50)
prepped <- prep(rec)
ncol(bake(prepped, new_data = dat[301:368, -1]))
tidy(prepped, number = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.