我正在创建一个配方,所以我首先创建了一个名为"response“的计算列:
rec <- recipe( ~., data = training) %>%
step_mutate(response = as.integer(all(c('A', 'B') %in% Col4) & Col4 == 'A'))我现在将这个新的计算列指定为recipe()函数中的response变量,如下所示。我将对其执行一系列操作,例如使用step_naomit执行的第一个操作。如何使用配方将recipe()中的响应重新指定为上一步(上面)的计算列?
recipe <- recipe(response ~ ., data = training) %>%
step_naomit(recipe, response)发布于 2021-10-25 21:54:58
通过明确设置role=参数,可以在step_mutate()函数中为新列设置角色。
rec <- recipe( ~., data = iris) %>%
step_mutate(SepalSquared= Sepal.Length ^ 2, role="outcome")然后检查它是否能与summary(prep(rec))一起工作
variable type role source
<chr> <chr> <chr> <chr>
1 Sepal.Length numeric predictor original
2 Sepal.Width numeric predictor original
3 Petal.Length numeric predictor original
4 Petal.Width numeric predictor original
5 Species nominal predictor original
6 SepalSquared numeric outcome derived 发布于 2021-10-26 07:19:05
这与tidymodel error, when calling predict function is asking for target variable相关
通常不建议修改食谱中的响应。这是因为在某些情况下,响应变量将不可用于配方,例如使用{tune}时。我建议您在将数据传递到配方之前执行此转换。如果你在验证拆分之前就做了,那就更好了。
set.seed(1234)
data_split <- my_data %>%
step_mutate(response = as.integer(all(c('A', 'B') %in% Col4) & Col4 == 'A')) %>%
initial_split()
training <- training(data_split)
testing <- testing(data_split)
rec <- recipe(response ~., data = training)https://stackoverflow.com/questions/69715107
复制相似问题