nested_cv
可用于获取一个重采样过程的结果,并在每次分割内进行进一步的重采样。可以使用 rsample
中使用的任何类型的重采样。
参数
- data
-
一个 DataFrame 。
- outside
-
初始重采样规范。这可以是已创建的对象或新对象的表达式(请参见下面的示例)。如果使用后者,则不需要指定
data
参数,如果给出,则将被忽略。 - inside
-
要在初始过程中进行的重采样类型的表达式。
值
带有 nested_cv
类和外部重采样过程通常包含的任何其他类的 tibble。结果包括外部数据拆分对象的列、一个或多个 id
列以及一列名为 inner_resamples
的嵌套 tibbles 列(带有附加重新采样)。
例子
## Using expressions for the resampling procedures:
nested_cv(mtcars, outside = vfold_cv(v = 3), inside = bootstraps(times = 5))
#> # Nested resampling:
#> # outer: 3-fold cross-validation
#> # inner: Bootstrap sampling
#> # A tibble: 3 × 3
#> splits id inner_resamples
#> <list> <chr> <list>
#> 1 <split [21/11]> Fold1 <boot [5 × 2]>
#> 2 <split [21/11]> Fold2 <boot [5 × 2]>
#> 3 <split [22/10]> Fold3 <boot [5 × 2]>
## Using an existing object:
folds <- vfold_cv(mtcars)
nested_cv(mtcars, folds, inside = bootstraps(times = 5))
#> # Nested resampling:
#> # outer: `folds`
#> # inner: Bootstrap sampling
#> # A tibble: 10 × 3
#> splits id inner_resamples
#> <list> <chr> <list>
#> 1 <split [28/4]> Fold01 <boot [5 × 2]>
#> 2 <split [28/4]> Fold02 <boot [5 × 2]>
#> 3 <split [29/3]> Fold03 <boot [5 × 2]>
#> 4 <split [29/3]> Fold04 <boot [5 × 2]>
#> 5 <split [29/3]> Fold05 <boot [5 × 2]>
#> 6 <split [29/3]> Fold06 <boot [5 × 2]>
#> 7 <split [29/3]> Fold07 <boot [5 × 2]>
#> 8 <split [29/3]> Fold08 <boot [5 × 2]>
#> 9 <split [29/3]> Fold09 <boot [5 × 2]>
#> 10 <split [29/3]> Fold10 <boot [5 × 2]>
## The dangers of outer bootstraps:
set.seed(2222)
bad_idea <- nested_cv(mtcars,
outside = bootstraps(times = 5),
inside = vfold_cv(v = 3)
)
#> Warning: Using bootstrapping as the outer resample is dangerous since the inner resample might have the same data point in both the analysis and assessment set.
first_outer_split <- bad_idea$splits[[1]]
outer_analysis <- as.data.frame(first_outer_split)
sum(grepl("Volvo 142E", rownames(outer_analysis)))
#> [1] 0
## For the 3-fold CV used inside of each bootstrap, how are the replicated
## `Volvo 142E` data partitioned?
first_inner_split <- bad_idea$inner_resamples[[1]]$splits[[1]]
inner_analysis <- as.data.frame(first_inner_split)
inner_assess <- as.data.frame(first_inner_split, data = "assessment")
sum(grepl("Volvo 142E", rownames(inner_analysis)))
#> [1] 0
sum(grepl("Volvo 142E", rownames(inner_assess)))
#> [1] 0
相关用法
- R rsample validation_set 创建验证拆分以进行调整
- R rsample initial_split 简单的训练/测试集分割
- R rsample populate 添加评估指标
- R rsample int_pctl 自举置信区间
- R rsample vfold_cv V 折交叉验证
- R rsample rset_reconstruct 使用新的 rset 子类扩展 rsample
- R rsample group_mc_cv 小组蒙特卡罗交叉验证
- R rsample group_vfold_cv V 组交叉验证
- R rsample rolling_origin 滚动原点预测重采样
- R rsample reverse_splits 反转分析和评估集
- R rsample group_bootstraps 团体自举
- R rsample labels.rset 从 rset 对象中查找标签
- R rsample get_fingerprint 获取重采样的标识符
- R rsample bootstraps 引导抽样
- R rsample validation_split 创建验证集
- R rsample reg_intervals 具有线性参数模型的置信区间的便捷函数
- R rsample clustering_cv 集群交叉验证
- R rsample initial_validation_split 创建初始训练/验证/测试拆分
- R rsample get_rsplit 从 rset 中检索单个 rsplit 对象
- R rsample loo_cv 留一交叉验证
- R rsample complement 确定评估样本
- R rsample slide-resampling 基于时间的重采样
- R rsample as.data.frame.rsplit 将 rsplit 对象转换为 DataFrame
- R rsample labels.rsplit 从 rsplit 对象中查找标签
- R rsample mc_cv 蒙特卡罗交叉验证
注:本文由纯净天空筛选整理自Hannah Frick等大神的英文原创作品 Nested or Double Resampling。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。