我是recipes
API 新手,遇到了一些问题。当我删除了某些我不感兴趣的功能时,为什么我不能bake
或我的食谱步骤?juice
set.seed(999)
train_test_split <- initial_split(mtcars)
mtcars_train <- training(train_test_split)
mtcars_test <- testing(train_test_split)
mtcars_train %>%
recipe(mpg ~ cyl + disp + hp + gear) %>%
step_rm(qsec, vs, carb) %>%
step_center(all_numeric()) %>%
step_scale(all_numeric()) %>%
prep(training = mtcars_train)
结果是:
Error in .f(.x[[i]], ...) : object 'qsec' not found
这很烦人,因为这意味着在应用步骤后,我需要在测试集和训练集上手动删除行:
rec_scale <- mtcars %>%
recipe(mpg ~ cyl + disp + hp + gear) %>%
step_center(all_numeric()) %>%
step_scale(all_numeric()) %>%
prep(training = mtcars_train)
train <- juice(rec_scale) %>%
select(-qsec, -vs, -carb)
test <- bake(rec_scale, mtcars_test) %>%
select(-qsec, -vs, -carb)
我想错了吗?我也可以事先过滤,但我认为我的食谱应该包括这样的东西。