【问题标题】:How to exclude certain variables from recipe?如何从配方中排除某些变量?
【发布时间】:2018-09-03 13:31:10
【问题描述】:

当使用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】:

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

    rec &lt;- rec %&gt;% add_role(description, new_role = "dont_use")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-02
      • 2011-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多