调优随机森林模型
现在您已经有了可用的逻辑回归模型,接下来请准备一个随机森林模型,用于与其对比。
本练习是课程的一部分
Tidyverse 中的机器学习
练习说明
- 使用
crossing()基于取值为 2、4、8、16 的mtry扩展交叉验证数据。 - 为每个折数与 mtry 的组合构建随机森林模型。
交互式实操练习
通过完成这段示例代码来试试这个练习。
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)))