微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用自定义范围或值调整工作流程中的配方

如何解决使用自定义范围或值调整工作流程中的配方

我正在尝试使用 tidymodels 中的 workflow_set() 函数来评估一批模型。 我知道可以修改某些模型规范以更改搜索范围,例如,鉴于此规范:

spec_lin <- linear_reg( penalty = tune(),mixture = tune()  ) %>%
set_engine('glmnet')

我可以使用以下方法修改范围:

rec_base <- recipe( price ~ feat_1) %>% 
  step_novel(feat_1) %>% 
  step_other(feat_1,threshold=.2 ) %>%
  step_dummy(feat_1)

rec_adv_param <- rec_base %>% 
  parameters() %>% 
  update ( mixture = mixture(c(0.1,0.01)) )

我的尝试是使用配方中的参数来做同样的事情。例如:

rec_tuned <- recipe( price ~ feat_1) %>% 
  step_novel(feat_1) %>% 
  step_other(feat_1,threshold=tune() ) %>%
  step_dummy(feat_1)

关注

rec_adv_param <- rec_tuned %>% 
  parameters() %>% 
  update ( threshold = threshold(c(0.1,0.2)) )

但是,当我尝试在工作流集()定义中使用它时,如果我使用类似的东西

wf_set  <- workflow_set(recipes,models,cross = TRUE ) 
  option_add(param_info = rec_adv_param,id = "rec_tuned_spec_lin") 

大结局“wf_set”丢失了他原来的调音参数,已经随同

threshold = threshold(c(0.1,0.2)

有没有办法在所有工作流集模型中添加配方的参数规范?

谢谢

解决方法

您可以通过 option_add() 为配方添加参数,如果您离开 id,则可以通过 id = NULL 为单个工作流添加所有工作流。当您对重新采样的数据进行调整或拟合时,将使用这些选项。

例如,如果我们想尝试 0 到 20 个 PCA 组件(而不是默认的):

library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#>   method                   from   
#>   required_pkgs.model_spec parsnip
data(Chicago)
data("chi_features_set")

time_val_split <-
   sliding_period(
      Chicago,date,"month",lookback = 38,assess_stop = 1
   )

## notice that there are no options; defaults will be used
chi_features_set
#> # A workflow set/tibble: 3 × 4
#>   wflow_id         info             option    result    
#>   <chr>            <list>           <list>    <list>    
#> 1 date_lm          <tibble [1 × 4]> <opts[0]> <list [0]>
#> 2 plus_holidays_lm <tibble [1 × 4]> <opts[0]> <list [0]>
#> 3 plus_pca_lm      <tibble [1 × 4]> <opts[0]> <list [0]>

## make new params
pca_param <-
   parameters(num_comp()) %>%
   update(num_comp = num_comp(c(0,20)))

## add new params to workflowset like this:
chi_features_set %>%
   option_add(param_info = pca_param,id = "plus_pca_lm")
#> # A workflow set/tibble: 3 × 4
#>   wflow_id         info             option    result    
#>   <chr>            <list>           <list>    <list>    
#> 1 date_lm          <tibble [1 × 4]> <opts[0]> <list [0]>
#> 2 plus_holidays_lm <tibble [1 × 4]> <opts[0]> <list [0]>
#> 3 plus_pca_lm      <tibble [1 × 4]> <opts[1]> <list [0]>

## now these new parameters can be used by `workflow_map()`:
chi_features_set %>%
   option_add(param_info = pca_param,id = "plus_pca_lm") %>%
   workflow_map(resamples = time_val_split,grid = 21,seed = 1)

#> # A workflow set/tibble: 3 × 4
#>   wflow_id         info             option    result   
#>   <chr>            <list>           <list>    <list>   
#> 1 date_lm          <tibble [1 × 4]> <opts[2]> <rsmp[+]>
#> 2 plus_holidays_lm <tibble [1 × 4]> <opts[2]> <rsmp[+]>
#> 3 plus_pca_lm      <tibble [1 × 4]> <opts[3]> <tune[+]>

reprex package (v2.0.0) 于 2021 年 7 月 30 日创建

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?