I'm new to recipes
and having some issues with the API. Why can't I bake
or juice
my recipe steps when I've removed certain features that I'm not interested in?
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)
results in:
Error in .f(.x[[i]], ...) : object 'qsec' not found
Which is pretty annoying because that means that I'll need to remove rows manually on both the test and train sets after steps have been applied:
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)
Am I thinking about this wrong? I could alternatively filter beforehand, but I would think that my recipe should include things like that.