調整 random forest 模型
既然你已經有可用的羅吉斯迴歸模型,接下來要準備一個 random forest 模型,方便與它比較。
本練習屬於課程
Tidyverse 的 Machine Learning
練習說明
- 使用
crossing(),針對mtry的取值 2、4、8、16,擴增交叉驗證資料。 - 為每個 fold 與 mtry 的組合建立 random forest 模型。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
library(ranger)
# Prepare for tuning your cross validation folds by varying mtry
cv_tune <- cv_data %>%
crossing(mtry = c(___))
# Build a cross validation model for each fold & mtry combination
cv_models_rf <- cv_tune %>%
mutate(model = map2(___, ___, ~ranger(formula = Attrition~.,
data = .x, mtry = .y,
num.trees = 100, seed = 42)))