食谱失败,插入符:: train

时间:2019-11-19 09:46:16

标签: r r-caret r-recipes

caretrecipes一起使用时,出现错误消息:

Error in { : task 1 failed - "$ operator is invalid for atomic vectors"

我设法将其范围缩小到配方问题。但是我不确定我在做什么错。有人看过吗?我发现的唯一相关信息是here,其中指出:

  

当模型对象失败并且没有引起配方时会发生这种情况   可用

以下遵循我使用的代码。我无法共享数据,但是在使用mtcar时也会出现错误。

library(caret)
library(tidymodels)
library(embed)
library(doParallel)

cluster <- makeCluster(detectCores() - 1) 
registerDoParallel(cluster)

df <- mtcars %>% 
  as_tibble() %>% 
  mutate(cyl = factor(cyl)) # to have one nominal variable

set.seed(123)
cv_split <- initial_split(df)
df_train <- training(cv_split)

set.seed(123)
cv_folds <- vfold_cv(df_train, v = 10, repeats = 10)

cv_ind <- rsample2caret(cv_folds)

rec <- 
  recipe(mpg ~ ., data = df_train) %>% 
  step_nzv(all_predictors()) %>% 
  step_lencode_mixed(all_nominal(), outcome = vars(mpg))

ctrl <- 
  trainControl(
    method = "repeatedcv",
    repeats = 10,
    index = cv_ind$index,
    indexOut = cv_ind$indexOut,
    allowParallel = TRUE)

train(rec,
    data = df_train,
    method = "glmnet",
    tuneLength = 20,
    trControl = ctrl)`

0 个答案:

没有答案