評估
該是檢驗成果的時候了。請微調你的模型以找出最佳的 penalty 值,並擬合最終模型來評估你的成果。
你的 workflow、penalty 的網格,以及你自行定義的 class_evaluate() 函式都已在環境中可用。
本練習屬於課程
R 的特徵工程
練習說明
- 設定一個
tune_grid,以 ROC_AUC 作為指標來探索模型表現。 - 選出最佳的 penalty 值。
- 使用最佳的 penalty 擬合最終的 workflow。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Set up a tune grid to explore your model performance against roc_auc
lr_tune_output <- ___(lr_workflow, resamples = vfold_cv(train, v = 5),
metrics = metric_set(roc_auc), grid = lr_penalty_grid)
# Select the best penalty value
best_penalty <- ___(lr_tune_output, metric = 'roc_auc', desc(penalty))
# Fit the final workflow with the best penalty
lr_final_fit<- ___(lr_workflow, best_penalty) %>% fit(data = train)
lr_final_fit %>% augment(test) %>%
class_evaluate(truth = Attrition, estimate = .pred_class, .pred_Yes)