workflow
中,提供了两次数据:在
recipe
调用和
vfold_cv
调用中。如果
recipe
对数据执行一些预处理而
vfold_cv
函数不执行,这不会导致冲突吗?似乎
recipe
可以安排和扩展虚拟对象等,从而改变观察的顺序和数据框中列的数据类型。
library(tidymodels)
model <- workflow() |>
add_recipe(
recipe(mpg ~ wt + cyl + drat + qsec + vs + am, data = mtcars) |> # here
step_scale() |>
step_center()
) |>
add_model(
linear_reg(penalty = tune()) |>
set_engine("glmnet")
) |>
tune_grid(
resamples = vfold_cv(v = 5, data = mtcars), # and here
#grid = 30 # doesn't capture the minimum rmse
grid = tibble(penalty = 10^seq(-8, 1, length.out = 40))
)
#> Warning: package 'glmnet' was built under R version 4.3.3
#> → A | warning: A correlation computation is required, but `estimate` is constant and has 0
#> standard deviation, resulting in a divide by 0 error. `NA` will be returned.
#> There were issues with some computations A: x1There were issues with some computations A: x2There were issues with some computations A: x4There were issues with some computations A: x5
model |>
autoplot()