Skip to contents

step_hai_scale_zero_one creates a a specification of a recipe step that will convert numeric data into from a time series into its velocity.

Usage

step_hai_scale_zero_one(
  recipe,
  ...,
  role = "predictor",
  trained = FALSE,
  columns = NULL,
  skip = FALSE,
  id = rand_id("hai_scale_zero_one")
)

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 that will be used to create the new variables. The selected variables should have class numeric

role

For model terms created by this step, what analysis role should they be assigned?. By default, the function assumes that the new variable 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.

columns

A character string of variables that will be used as inputs. This field is a placeholder and will be populated once recipes::prep() is used.

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.

Value

For step_hai_scale_zero_one, an updated version of recipe with the new step added to the sequence of existing steps (if any).

Main Recipe Functions:

Details

Numeric Variables Unlike other steps, step_hai_scale_zero_one does not remove the original numeric variables. recipes::step_rm() can be used for this purpose.

Examples

suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(recipes))

data_tbl <- data.frame(a = rnorm(200, 3, 1), b = rnorm(200, 2, 2))

# Create a recipe object
rec_obj <- recipe(a ~ ., data = data_tbl) %>%
  step_hai_scale_zero_one(b)

# View the recipe object
rec_obj
#> 
#> ── Recipe ──────────────────────────────────────────────────────────────────────
#> 
#> ── Inputs 
#> Number of variables by role
#> outcome:   1
#> predictor: 1
#> 
#> ── Operations 
#>  Zero-One Scale Transformation on: b

# Prepare the recipe object
prep(rec_obj)
#> 
#> ── Recipe ──────────────────────────────────────────────────────────────────────
#> 
#> ── Inputs 
#> Number of variables by role
#> outcome:   1
#> predictor: 1
#> 
#> ── Training information 
#> Training data contained 200 data points and no incomplete rows.
#> 
#> ── Operations 
#>  Zero-One Scale Transformation on: b | Trained

# Bake the recipe object - Adds the Time Series Signature
bake(prep(rec_obj), data_tbl)
#> # A tibble: 200 × 3
#>        b     a hai_scale_zero_one_b
#>    <dbl> <dbl>                <dbl>
#>  1  4.01  3.33                0.658
#>  2  4.62  2.42                0.722
#>  3  6.20  3.43                0.886
#>  4  4.74  3.84                0.735
#>  5  2.68  2.53                0.520
#>  6  1.55  3.47                0.402
#>  7  5.14  3.36                0.776
#>  8  4.49  4.07                0.709
#>  9  3.94  4.43                0.651
#> 10  1.59  2.40                0.406
#> # ℹ 190 more rows

rec_obj %>%
  prep() %>%
  juice()
#> # A tibble: 200 × 3
#>        b     a hai_scale_zero_one_b
#>    <dbl> <dbl>                <dbl>
#>  1  4.01  3.33                0.658
#>  2  4.62  2.42                0.722
#>  3  6.20  3.43                0.886
#>  4  4.74  3.84                0.735
#>  5  2.68  2.53                0.520
#>  6  1.55  3.47                0.402
#>  7  5.14  3.36                0.776
#>  8  4.49  4.07                0.709
#>  9  3.94  4.43                0.651
#> 10  1.59  2.40                0.406
#> # ℹ 190 more rows