如何从配方中排除某些变量?

How to exclude certain variables from recipe?

当使用 step_regex 函数为模型构建配方时,它会为原始列中的某些模式创建额外的列。有没有办法在我完成后从配方中排除原始列?

例如在下面的示例中,产品包含原始 description 列和两个由 step_regex 新创建的列。我想要一个与 recipe 对象集成的解决方案,以便我可以直接在 caret::train.

中使用它
library(recipe)
data(covers)

rec <- recipe(~ description, covers) %>%
  step_regex(description, pattern = "(rock|stony)", result = "rocks") %>%
  step_regex(description, pattern = "ratake families")

rec2 <- prep(rec, training = covers)

with_dummies <- bake(rec2, newdata = covers)

刚刚找到解决方案。我想我可以更改我不想用作预测变量的列的角色。

rec <- rec %>% add_role(description, new_role = "dont_use")