rset_reconstruct()
封裝了允許新的 rset 子類與 vctrs (通過 vctrs::vec_restore()
)和 dplyr (通過 dplyr::dplyr_reconstruct()
)正常工作的邏輯。它旨在成為一個開發人員工具,正常使用 rsample 不需要它。
細節
在 vctrs/dplyr 操作之後,如果滿足以下條件,則將 rset 對象視為"reconstructable":
-
x
和to
都有一個名為"splits"
的相同列(列和行順序無關緊要)。 -
x
和to
都有相同的列,前綴為"id"
(列和行順序無關緊要)。
例子
to <- bootstraps(mtcars, times = 25)
# Imitate a vctrs/dplyr operation,
# where the class might be lost along the way
x <- tibble::as_tibble(to)
# Say we added a new column to `x`. Here we mock a `mutate()`.
x$foo <- "bar"
# This is still reconstructable to `to`
rset_reconstruct(x, to)
#> # Bootstrap sampling
#> # A tibble: 25 × 3
#> splits id foo
#> <list> <chr> <chr>
#> 1 <split [32/12]> Bootstrap01 bar
#> 2 <split [32/9]> Bootstrap02 bar
#> 3 <split [32/13]> Bootstrap03 bar
#> 4 <split [32/12]> Bootstrap04 bar
#> 5 <split [32/12]> Bootstrap05 bar
#> 6 <split [32/13]> Bootstrap06 bar
#> 7 <split [32/11]> Bootstrap07 bar
#> 8 <split [32/12]> Bootstrap08 bar
#> 9 <split [32/14]> Bootstrap09 bar
#> 10 <split [32/12]> Bootstrap10 bar
#> # ℹ 15 more rows
# Say we lose the first row
x <- x[-1, ]
# This is no longer reconstructable to `to`, as `x` is no longer an rset
# bootstraps object with 25 bootstraps if one is lost!
rset_reconstruct(x, to)
#> # A tibble: 24 × 3
#> splits id foo
#> <list> <chr> <chr>
#> 1 <split [32/9]> Bootstrap02 bar
#> 2 <split [32/13]> Bootstrap03 bar
#> 3 <split [32/12]> Bootstrap04 bar
#> 4 <split [32/12]> Bootstrap05 bar
#> 5 <split [32/13]> Bootstrap06 bar
#> 6 <split [32/11]> Bootstrap07 bar
#> 7 <split [32/12]> Bootstrap08 bar
#> 8 <split [32/14]> Bootstrap09 bar
#> 9 <split [32/12]> Bootstrap10 bar
#> 10 <split [32/10]> Bootstrap11 bar
#> # ℹ 14 more rows
相關用法
- R rsample rolling_origin 滾動原點預測重采樣
- R rsample reverse_splits 反轉分析和評估集
- R rsample reg_intervals 具有線性參數模型的置信區間的便捷函數
- R rsample reshuffle_rset “重新洗牌”一個 rset 以重新生成具有相同參數的新 rset
- R rsample validation_set 創建驗證拆分以進行調整
- R rsample initial_split 簡單的訓練/測試集分割
- R rsample populate 添加評估指標
- R rsample int_pctl 自舉置信區間
- R rsample vfold_cv V 折交叉驗證
- R rsample group_mc_cv 小組蒙特卡羅交叉驗證
- R rsample group_vfold_cv V 組交叉驗證
- R rsample group_bootstraps 團體自舉
- R rsample labels.rset 從 rset 對象中查找標簽
- R rsample get_fingerprint 獲取重采樣的標識符
- R rsample bootstraps 引導抽樣
- R rsample validation_split 創建驗證集
- 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等大神的英文原創作品 Extending rsample with new rset subclasses。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。