Hiệu năng random forest
Đã đến lúc kiểm tra xem các mô hình random forest bạn đã xây dựng ở bài trước có vượt trội hơn mô hình logistic regression hay không.
Nhớ rằng recall trên tập validate của mô hình logistic regression là 0,43.
Bài tập này là một phần của khóa học
Machine Learning trong tidyverse
Hướng dẫn bài tập
- Chuẩn bị các cột
validate_actualvàvalidate_predictedcho từng tổ hợp mtry/fold. - Tính recall cho từng tổ hợp mtry/fold.
- Tính recall trung bình cho mỗi giá trị của
mtry.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
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(___))