如何从食谱中排除某些变量?

问题描述 投票:1回答:1

使用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)
r r-caret r-recipes
1个回答
1
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.