ランダムフォレストモデルをチューニングする
ロジスティック回帰モデルが動くようになったので、比較のためにランダムフォレストモデルを用意しましょう。
この演習はコースの一部です
Tidyverse で学ぶ Machine Learning
演習の手順
crossing()を使って、mtryの値 2、4、8、16 を用いたクロスバリデーション用データを展開します。- 各 fold と 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)))