| step_bin_spectra | R Documentation |
step_bin_spectra() creates a specification of a recipe step that
replaces each group of width adjacent channels of the spectra by their
mean, with bin_spectra().
step_bin_spectra(
recipe,
...,
width = 3,
segments = TRUE,
role = "predictor",
trained = FALSE,
columns = NULL,
bins = NULL,
skip = FALSE,
id = recipes::rand_id("bin_spectra")
)
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 |
width |
The number of adjacent channels averaged, a positive integer.
Default is 3; |
segments |
A logical: bin the segments between gaps of the
wavelength axis separately ( |
role |
The role of the binned columns. Default is |
trained |
A logical indicating whether the step has been trained. |
columns |
The names of the selected columns, stored once the step has been trained. |
bins |
The groups of channels and the names of the binned columns, set when the recipe is prepped. Not to be set by the user. |
skip |
A logical. Should the step be skipped when the recipe is baked
by |
id |
A character string that is unique to this step. |
The selected columns form one spectrum per row, and are replaced by the
fewer binned columns, named by their mean wavelength (see
bin_spectra()). The groups of channels are set from the column names
when the recipe is prepped; nothing is estimated from the training data.
The width can be tuned with tune::tune() (dials parameter
window_size()). tidy() returns the terms,
width and id.
An updated version of recipe with the new step added to the
sequence of existing steps.
bin_spectra(), step_gap_derivative(), step_spectral_norm()
if (rlang::is_installed("recipes")) {
data(forageLIBS)
# binning, normalization to the total area and gap-segment derivative
rec <- recipes::recipe(K ~ ., data = forageLIBS[-c(1:10, 12:14)]) |>
step_bin_spectra(recipes::all_predictors(), width = 3) |>
step_spectral_norm(recipes::all_predictors(), method = "area") |>
step_gap_derivative(recipes::all_predictors(), gap = 3, segment = 1) |>
recipes::prep()
dim(recipes::bake(rec, new_data = NULL))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.