首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >tidymodels中的错误-工作流集:提供的` not‘有以下参数列,这些列尚未被“tuning ()”标记为调优

tidymodels中的错误-工作流集:提供的` not‘有以下参数列,这些列尚未被“tuning ()”标记为调优
EN

Stack Overflow用户
提问于 2022-04-02 02:32:15
回答 1查看 419关注 0票数 0

我尝试使用工作流集、包或方法来获得错误。以下是R码(抱歉,代码很长):

代码语言:javascript
复制
# Package ----
library(finetune)
library(themis)
library(tidymodels)

# Data ----
data("PimaIndiansDiabetes", package = "mlbench")

table(PimaIndiansDiabetes$diabetes)
str(PimaIndiansDiabetes)
PimaIndiansDiabetes <- 
  PimaIndiansDiabetes %>% 
  mutate(diabetes = relevel(diabetes, "pos"))

# Split ----
set.seed(123)
ind <- initial_split(PimaIndiansDiabetes, strata = diabetes)

dat_train <- training(ind)
dat_test <- testing(ind)

# CV ----
set.seed(123)
dat_cv <- vfold_cv(dat_train, v = 10)

# Recipe ----
dat_rec <- 
  dat_train %>% 
  recipe(diabetes ~.) %>% 
  step_normalize(all_numeric_predictors()) %>% 
  step_smote(diabetes)

# Model ----
parsnip_nn <- 
  mlp(hidden_units = tune(),
      penalty = tune(),
      epochs = tune()) %>% 
  set_mode("classification") %>% 
  set_engine("nnet")

parsnip_log <- 
  logistic_reg(penalty = tune(),
               mixture = tune()) %>% 
  set_engine("glmnet")

# Latin hypercube grid ----
latin_grid <- 
  grid_latin_hypercube(penalty(),
                       mixture(),
                       hidden_units(),
                       epochs(),
                       size = 30)

# Tuning ----
race_ctrl <-
  control_race(
    save_pred = T,
    save_workflow = T,
    verbose = T
  )

class_metrics <- metric_set(accuracy, 
                            f_meas, 
                            j_index, 
                            kap, 
                            precision, 
                            sensitivity, 
                            specificity, 
                            roc_auc, 
                            mcc, 
                            pr_auc)

Tuned_results <- 
  workflow_set(
    preproc = list(rec = dat_rec),
    models = list(parsnip_nn = parsnip_nn,
                  parsnip_log = parsnip_log)
  ) %>% 
  workflow_map(
    fn = "tune_race_anova", 
    seed = 123,
    grid = latin_grid,
    resamples = dat_cv,
    verbose = T,
    metrics = class_metrics,
    control = race_ctrl
  )

这是我得到的错误,基本上说模型的一些参数没有被tune()识别。

代码语言:javascript
复制
i 1 of 2 tuning: rec_parsnip_nn
x 1 of 2 tuning: rec_parsnip_nn failed with: Error in check_grid(grid = grid, workflow = workflow, pset = pset) : The provided `grid` has the following parameter columns that have not been marked for tuning by `tune()`: 'mixture'.
i 2 of 2 tuning: rec_parsnip_log
x 2 of 2 tuning: rec_parsnip_log failed with: Error in check_grid(grid = grid, workflow = workflow, pset = pset) : The provided `grid` has the following parameter columns that have not been marked for tuning by `tune()`: 'hidden_units', 'epochs'.

如果我们检查一下grid_results

代码语言:javascript
复制
# A workflow set/tibble: 2 x 4
  wflow_id        info             option    result        
  <chr>           <list>           <list>    <list>        
1 rec_parsnip_nn  <tibble [1 x 4]> <opts[4]> <try-errr [1]>
2 rec_parsnip_log <tibble [1 x 4]> <opts[4]> <try-errr [1]>

我不知道为什么mixturehidden_unitsepochs等参数不为tune()所认可。知道我哪里做错了吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-02 21:50:04

神经网络没有一个名为mixture的参数,正则回归模型没有参数hidden_unitsepochs。对于这两个模型,您不能使用相同的参数grid,因为它们没有相同的超级参数。相反,您需要:

  • 为两个模型创建单独的网格
  • 使用option_add()通过id参数将每个网格添加到其模型中

还可以查看TMwR第15章,了解有关如何向特定工作流添加选项的详细信息。由于您使用的是拉丁超级立方体,这在tidymodel中是默认的,所以您可能想跳过所有这些,转而使用grid = 30

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71714430

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档