使用 blend_predictions()
評估數據堆棧後,某些候選數據將具有非零堆棧係數。此類候選者被稱為 "members." 由於成員的預測最終將告知模型堆棧的預測,因此應使用 fit_members()
在完整的訓練集上對成員進行訓練。
參數
- model_stack
-
blend_predictions()
輸出的model_stack
對象。 - ...
-
附加參數。目前被忽略。
細節
要並行適應成員,請注冊並行後端函數。有關示例,請參閱foreach::foreach()
的文檔。
示例數據
該軟件包提供了一些重采樣對象和數據集,用於源自對 1212 個red-eyed 樹蛙胚胎的研究的示例和小插圖!
如果 Red-eyed 樹蛙 (RETF) 胚胎檢測到潛在的捕食者威脅,它們的孵化時間可能會比正常情況下的 7 天更早。研究人員想要確定這些樹蛙胚胎如何以及何時能夠檢測到來自環境的刺激。為此,他們通過用鈍探針搖動胚胎,對不同發育階段的胚胎進行"predator stimulus"測試。盡管一些胚胎事先接受了慶大黴素處理,慶大黴素是一種可以消除側線(感覺器官)的化合物。研究員朱莉·榮格(Julie Jung)和她的團隊發現,這些因子決定了胚胎是否過早孵化!
請注意,stacks 包中包含的數據不一定是完整數據集的代表性或無偏差子集,並且僅用於演示目的。
reg_folds
和 class_folds
是來自 rsample
的 rset
交叉驗證對象,分別將訓練數據分為回歸模型對象和分類模型對象。 tree_frogs_reg_test
和tree_frogs_class_test
是類似的測試集。
reg_res_lr
、reg_res_svm
和 reg_res_sp
分別包含線性回歸、支持向量機和樣條模型的回歸調整結果,擬合 latency
(即胚胎響應抖動需要多長時間孵化)在 tree_frogs
數據中,使用大多數其他變量作為預測變量。請注意,這些模型背後的數據經過過濾,僅包含來自響應刺激而孵化的胚胎的數據。
class_res_rf
和 class_res_nn
分別包含隨機森林和神經網絡分類模型的多類分類調整結果,使用大多數其他變量作為預測變量在數據中擬合 reflex
(耳朵函數的度量)。
log_res_rf
和 log_res_nn
分別包含隨機森林和神經網絡分類模型的二元分類調整結果,使用大多數其他變量擬合 hatched
(無論胚胎是否響應刺激而孵化)預測因子。
請參閱?example_data
了解有關這些對象的更多信息,並瀏覽生成它們的源代碼。
也可以看看
其他核心動詞:add_candidates()
、blend_predictions()
、stacks()
例子
# see the "Example Data" section above for
# clarification on the objects used in these examples!
# put together a data stack
reg_st <-
stacks() %>%
add_candidates(reg_res_lr) %>%
add_candidates(reg_res_svm) %>%
add_candidates(reg_res_sp)
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
#> # reg_res_sp: 10 model configurations
#> # Outcome: latency (numeric)
# evaluate the data stack and fit the member models
reg_st %>%
blend_predictions() %>%
fit_members()
#> ── A stacked ensemble model ─────────────────────────────────────
#>
#> Out of 16 possible candidate members, the ensemble retained 3.
#> Penalty: 0.1.
#> Mixture: 1.
#>
#> The 3 highest weighted members are:
#> # A tibble: 3 × 3
#> member type weight
#> <chr> <chr> <dbl>
#> 1 reg_res_svm_1_3 svm_rbf 0.636
#> 2 reg_res_sp_03_1 linear_reg 0.484
#> 3 reg_res_sp_10_1 linear_reg 0.0496
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
#> # reg_res_sp: 10 model configurations
#> # Outcome: latency (numeric)
# do the same with multinomial classification models
class_st <-
stacks() %>%
add_candidates(class_res_nn) %>%
add_candidates(class_res_rf) %>%
blend_predictions() %>%
fit_members()
#> Warning: Predictions from 1 candidate were identical to those from existing
#> candidates and were removed from the data stack.
class_st
#> ── A stacked ensemble model ─────────────────────────────────────
#>
#> Out of 21 possible candidate members, the ensemble retained 8.
#> Penalty: 0.01.
#> Mixture: 1.
#> Across the 3 classes, there are an average of 4 coefficients per class.
#>
#> The 8 highest weighted member classes are:
#> # A tibble: 8 × 4
#> member type weight class
#> <chr> <chr> <dbl> <fct>
#> 1 .pred_full_class_res_nn_1_1 mlp 23.3 full
#> 2 .pred_mid_class_res_nn_1_1 mlp 1.89 mid
#> 3 .pred_mid_class_res_rf_1_06 rand_forest 1.71 mid
#> 4 .pred_mid_class_res_rf_1_10 rand_forest 1.17 mid
#> 5 .pred_full_class_res_rf_1_03 rand_forest 0.407 full
#> 6 .pred_full_class_res_rf_1_05 rand_forest 0.222 full
#> 7 .pred_full_class_res_rf_1_01 rand_forest 0.00160 full
#> 8 .pred_full_class_res_rf_1_02 rand_forest 0.000322 full
# ...or binomial classification models
log_st <-
stacks() %>%
add_candidates(log_res_nn) %>%
add_candidates(log_res_rf) %>%
blend_predictions() %>%
fit_members()
log_st
#> ── A stacked ensemble model ─────────────────────────────────────
#>
#> Out of 11 possible candidate members, the ensemble retained 3.
#> Penalty: 1e-06.
#> Mixture: 1.
#>
#> The 3 highest weighted member classes are:
#> # A tibble: 3 × 3
#> member type weight
#> <chr> <chr> <dbl>
#> 1 .pred_no_log_res_nn_1_1 mlp 7.38
#> 2 .pred_no_log_res_rf_1_05 rand_forest 3.42
#> 3 .pred_no_log_res_rf_1_02 rand_forest 0.100
相關用法
- R stacks axe_model_stack 砍掉 model_stack。
- R stacks predict.model_stack 使用模型堆棧進行預測
- R stacks add_candidates 將模型定義添加到數據堆棧
- R stacks blend_predictions 從數據堆棧中確定堆棧係數
- R stacks collect_parameters 收集候選參數和疊加係數
- R stlmethods STL 對象的方法
- R medpolish 矩陣的中值波蘭(穩健雙向分解)
- R naprint 調整缺失值
- R summary.nls 總結非線性最小二乘模型擬合
- R summary.manova 多元方差分析的匯總方法
- R formula 模型公式
- R nls.control 控製 nls 中的迭代
- R aggregate 計算數據子集的匯總統計
- R deriv 簡單表達式的符號和算法導數
- R kruskal.test Kruskal-Wallis 秩和檢驗
- R quade.test 四方測試
- R decompose 移動平均線的經典季節性分解
- R profile-methods stats4 包中的函數配置文件方法
- R plot.stepfun 繪製階躍函數
- R alias 查找模型中的別名(依賴項)
- R qqnorm 分位數-分位數圖
- R update-methods stats4包中函數更新的方法
- R eff.aovlist 多層方差分析的計算效率
- R pairwise.t.test 成對 t 檢驗
- R loglin 擬合對數線性模型
注:本文由純淨天空篩選整理自Max Kuhn等大神的英文原創作品 Fit model stack members with non-zero stacking coefficients。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。