計算交叉驗證的表現
為了達成模型目標,使用精心挑選的評估指標來最佳化模型非常關鍵。
想像在這個情境中,你希望用這個模型找出被預測將離職的員工。理想上,你要的是能盡可能抓住越多「準備離職」員工的模型,這樣你才能及時介入。能夠反映這個目標的對應指標就是「召回率(recall)」。因此,你將只使用召回率(recall)來最佳化並挑選模型。
本練習屬於課程
Tidyverse 的 Machine Learning
練習說明
- 針對每個分折,將實際值與預測值進行比較以計算召回率,並將結果指定到
validate_recall欄位。 - 印出
validate_recall欄位。 - 印出此欄位的平均值。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Calculate the validate recall for each cross validation fold
cv_perf_recall <- cv_prep_lr %>%
mutate(validate_recall = map2_dbl(___, ___,
~recall(actual = .x, predicted = .y)))
# Print the validate_recall column
cv_perf_recall$___
# Calculate the average of the validate_recall column
___