| step_wavelet | R Documentation |
step_wavelet() creates a specification of a recipe step that replaces
the spectral columns by their wavelet coefficients, computed with
wavelet_features(), optionally keeping only the coefficients of largest
variance in the training data.
step_wavelet(
recipe,
...,
wavelet = "d4",
level = 3,
coefficients = "approximation",
num_coef = NULL,
prefix = "wav_",
keep_original_cols = FALSE,
role = "predictor",
trained = FALSE,
columns = NULL,
res = NULL,
skip = FALSE,
id = recipes::rand_id("wavelet")
)
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 |
wavelet |
The wavelet: |
level |
The number of levels of the decomposition. Default is 3. |
coefficients |
The coefficients returned: |
num_coef |
The number of coefficients to keep, those of largest
variance in the training data, or |
prefix |
The prefix of the new column names. Default is |
keep_original_cols |
A logical: keep the spectral columns ( |
role |
Not used by this step, since no new variables are created. |
trained |
A logical indicating whether the step has been trained. |
columns |
The names of the selected columns, stored once the step has been trained. |
res |
The coefficients kept, stored once the step has been trained. 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. With num_coef, the
variance of each coefficient is computed on the training data when the
recipe is prepped, and the num_coef coefficients of largest variance are
kept (Trygg and Wold, 1998); new data get the same coefficients. The
level and num_coef can be tuned with tune::tune() (dials parameters
wavelet_level() and num_terms()). tidy()
returns the names of the kept coefficients (terms), the wavelength at
their center (see wavelet_features(); NA when the column names are not
wavelengths), their variance in the training data (NA before the step
is trained) and id.
An updated version of recipe with the new step added to the
sequence of existing steps.
wavelet_features(), step_savgol(), step_wavelet_denoise()
if (rlang::is_installed("recipes")) {
data(forageLIBS)
rec <- recipes::recipe(K ~ ., data = forageLIBS[-c(1:10, 12:14)]) |>
step_wavelet(recipes::all_predictors(), wavelet = "la8", level = 4, num_coef = 50) |>
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.