在使用tidymodels调优模型时,我遇到了此错误Error: Element ``id`` should have unique values. Duplicates exist for item(s): 'penalty', 'mixture"
。我花了一段时间才弄清错误的原因。我把它贴在这里,以防有人遇到同样的错误。
library(tidymodels)
#> ── Attaching packages ─────────────────────────────────────────────────────────────────── tidymodels 0.1.1 ──
#> ✓ broom 0.7.1 ✓ recipes 0.1.13
#> ✓ dials 0.0.9 ✓ rsample 0.0.8
#> ✓ dplyr 1.0.2 ✓ tibble 3.0.3
#> ✓ ggplot2 3.3.2 ✓ tidyr 1.1.2
#> ✓ infer 0.5.3 ✓ tune 0.1.1
#> ✓ modeldata 0.0.2 ✓ workflows 0.2.0
#> ✓ parsnip 0.1.3 ✓ yardstick 0.0.7
#> ✓ purrr 0.3.4
#> ── Conflicts ────────────────────────────────────────────────────────────────────── tidymodels_conflicts() ──
#> x purrr::discard() masks scales::discard()
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag() masks stats::lag()
#> x recipes::step() masks stats::step()
lr_spec <-
linear_reg() %>%
set_engine(
"glmnet",
penalty = tune(),
mixture = tune()) %>%
set_mode("regression")
parameters(lr_spec)
#> Error: Element `id` should have unique values. Duplicates exist for item(s): 'penalty', 'mixture'
由reprex包(v0.3.0(于2021-04-13创建
实际上,这是由于我方在定义lr_spec
时犯了一个愚蠢的错误。我定义了调谐参数CCD_ 3&penalty
在set_engine()
中,而它们本应在linear_reg()
中定义
library(tidymodels)
lr_spec <-
linear_reg(
penalty = tune(),
mixture = tune()) %>%
set_engine("glmnet") %>%
set_mode("regression")
parameters(lr_spec)
#> Collection of 2 parameters for tuning
#>
#> identifier type object
#> penalty penalty nparam[+]
#> mixture mixture nparam[+]
由reprex包(v0.3.0(于2021-04-13创建