将尖号与食谱一起使用会导致重采样困难

时间:2018-09-13 00:21:14

标签: r r-caret r-recipes

我一直在使用食谱将其插入caret::train,目前进展顺利,但是现在我尝试了一些step_transforms,但出现了错误:

Error in resamples.default(model_list) : 
  There are different numbers of resamples in each model

当我比较带有和不带有转换的模型时。与step_centrestep_scale相同的代码可以正常工作。

library(caret)
library(tidyverse)
library(tidymodels)

formula <- price ~ carat

model_recipe <- recipe(formula, data = diamonds)

quadratic_model_recipe <- recipe(formula, data = diamonds) %>% 
  step_poly(all_predictors())

model_list <- list(
  linear_model = NULL,
  quadratic  = NULL
)

model_list$linear_model <-
  model_recipe %>% train(
    data = diamonds,
    method = "lm",
    trControl = trainControl(method = "cv"))

model_list$quadratic_model <-
  quadratic_model_recipe %>% train(
    data = diamonds,
    method = "lm",
    trControl = trainControl(method = "cv"))

resamp <- resamples(model_list)

1 个答案:

答案 0 :(得分:0)

quadratic = NULL应该是quadratic_model = NULL