如何在 r 中使用食谱包中的 add_step

how to use add_step from recipes package in r

我想构建一个向食谱添加步骤的函数,但我不知道如何使用 add_step。文档中没有示例也于事无补。

这是我试过的:

suppressPackageStartupMessages(library(recipes))

rec1 <- recipe(data = mtcars, mpg ~ disp + hp)
rec1
#> Data Recipe
#> 
#> Inputs:
#> 
#>       role #variables
#>    outcome          1
#>  predictor          2

rec2 <- add_step(rec = rec1, step_mutate(hp = 1))
#> Error in add_step(recipe, step_mutate_new(terms = terms, trained = trained, : argument "recipe" is missing, with no default

reprex package (v0.3.0)

于 2020-02-24 创建

step_mutate 的代码为您完成调用 add_step 的工作。所以你基本上做了两次。它应该看起来更像

rec2 <- rec1 %>% step_mutate(hp = 1)