隨機森林效能
現在該檢視你在前一個練習建立的隨機森林模型,是否能勝過邏輯斯迴歸模型。
記住,邏輯斯迴歸模型在驗證集的 recall 為 0.43。
本練習屬於課程
Tidyverse 的 Machine Learning
練習說明
- 為每個 mtry/fold 組合建立
validate_actual與validate_predicted欄位。 - 計算每個 mtry/fold 組合的 recall。
- 計算各個
mtry值的 recall 平均值。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
cv_prep_rf <- cv_models_rf %>%
mutate(
# Prepare binary vector of actual Attrition values in validate
validate_actual = map(validate, ~.x$___ == "___"),
# Prepare binary vector of predicted Attrition values for validate
validate_predicted = map2(.x = ___, .y = ___, ~predict(.x, .y, type = "response")$predictions == "Yes")
)
# Calculate the validate recall for each cross validation fold
cv_perf_recall <- cv_prep_rf %>%
mutate(recall = map2_dbl(.x = ___, .y = ___, ~recall(actual = .x, predicted = .y)))
# Calculate the mean recall for each mtry used
cv_perf_recall %>%
group_by(___) %>%
summarise(mean_recall = mean(___))