当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R stacks collect_parameters 收集候选参数和叠加系数


帮助在堆栈中定位候选人的函数。接受数据堆栈或模型堆栈和候选名称,并返回将候选/成员名称映射到其超参数的 tibble(如果是模型堆栈,则还映射到其堆栈系数)。

用法

collect_parameters(stack, candidates, ...)

# S3 method for default
collect_parameters(stack, candidates, ...)

# S3 method for data_stack
collect_parameters(stack, candidates, ...)

# S3 method for model_stack
collect_parameters(stack, candidates, ...)

参数

stack

data_stackmodel_stack 对象。

candidates

要收集参数的候选人的姓名。这将是提供给 add_candidates()name 参数,或者(如果未提供)提供给 add_candidates() 中的 candidates 参数的对象名称。

...

附加参数。目前被忽略。

tibble::tbl_df 包含有关成员名称和超参数的信息。

示例数据

该软件包提供了一些重采样对象和数据集,用于源自对 1212 个red-eyed 树蛙胚胎的研究的示例和小插图!

如果 Red-eyed 树蛙 (RETF) 胚胎检测到潜在的捕食者威胁,它们的孵化时间可能会比正常情况下的 7 天更早。研究人员想要确定这些树蛙胚胎如何以及何时能够检测到来自环境的刺激。为此,他们通过用钝探针摇动胚胎,对不同发育阶段的胚胎进行"predator stimulus"测试。尽管一些胚胎事先接受了庆大霉素处理,庆大霉素是一种可以消除侧线(感觉器官)的化合物。研究员朱莉·荣格(Julie Jung)和她的团队发现,这些因子决定了胚胎是否过早孵化!

请注意,stacks 包中包含的数据不一定是完整数据集的代表性或无偏差子集,并且仅用于演示目的。

reg_foldsclass_folds 是来自 rsamplerset 交叉验证对象,分别将训练数据分为回归模型对象和分类模型对象。 tree_frogs_reg_testtree_frogs_class_test 是类似的测试集。

reg_res_lrreg_res_svmreg_res_sp 分别包含线性回归、支持向量机和样条模型的回归调整结果,拟合 latency(即胚胎响应抖动需要多长时间孵化)在 tree_frogs 数据中,使用大多数其他变量作为预测变量。请注意,这些模型背后的数据经过过滤,仅包含来自响应刺激而孵化的胚胎的数据。

class_res_rfclass_res_nn 分别包含随机森林和神经网络分类模型的多类分类调整结果,使用大多数其他变量作为预测变量在数据中拟合 reflex(耳朵函数的度量)。

log_res_rflog_res_nn 分别包含随机森林和神经网络分类模型的二元分类调整结果,使用大多数其他变量拟合 hatched(无论胚胎是否响应刺激而孵化)预测因子。

请参阅?example_data 了解有关这些对象的更多信息,并浏览生成它们的源代码。

例子

# see the "Example Data" section above for
# clarification on the objects used in these examples!

# put together a data stack using
# tuning results for regression models
reg_st <- 
  stacks() %>%
  add_candidates(reg_res_lr) %>%
  add_candidates(reg_res_svm) %>%
  add_candidates(reg_res_sp, "spline")
  
reg_st
#> # A data stack with 3 model definitions and 16 candidate members:
#> #   reg_res_lr: 1 model configuration
#> #   reg_res_svm: 5 model configurations
#> #   spline: 10 model configurations
#> # Outcome: latency (numeric)
  
# check out the hyperparameters for some of the candidates
collect_parameters(reg_st, "reg_res_svm")
#> # A tibble: 5 × 3
#>   member             cost     rbf_sigma
#>   <chr>             <dbl>         <dbl>
#> 1 reg_res_svm_1_1 3.09    0.000000465  
#> 2 reg_res_svm_1_2 9.56    0.00346      
#> 3 reg_res_svm_1_3 0.321   0.0256       
#> 4 reg_res_svm_1_4 0.00486 0.00000251   
#> 5 reg_res_svm_1_5 0.0146  0.00000000959

collect_parameters(reg_st, "spline")
#> # A tibble: 10 × 2
#>    member        age
#>    <chr>       <int>
#>  1 spline_01_1    12
#>  2 spline_02_1     6
#>  3 spline_03_1    15
#>  4 spline_04_1     5
#>  5 spline_05_1     3
#>  6 spline_06_1    13
#>  7 spline_07_1     9
#>  8 spline_08_1    10
#>  9 spline_09_1     7
#> 10 spline_10_1     2

# blend the data stack to view the hyperparameters 
# along with the stacking coefficients!
collect_parameters(
  reg_st %>% blend_predictions(), 
  "spline"
)
#> # A tibble: 10 × 3
#>    member        age   coef
#>    <chr>       <int>  <dbl>
#>  1 spline_01_1    12 0     
#>  2 spline_02_1     6 0     
#>  3 spline_03_1    15 0.486 
#>  4 spline_04_1     5 0     
#>  5 spline_05_1     3 0     
#>  6 spline_06_1    13 0     
#>  7 spline_07_1     9 0     
#>  8 spline_08_1    10 0     
#>  9 spline_09_1     7 0     
#> 10 spline_10_1     2 0.0482

相关用法


注:本文由纯净天空筛选整理自Max Kuhn等大神的英文原创作品 Collect candidate parameters and stacking coefficients。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。