拟合并评估模型
现在您已经处理了缺失值并创建了虚拟变量,是时候评估模型的表现了!
attrition 数据集、test 与 train 划分、lr_recipe,以及您已声明的 logistic_model() 都已为您加载。
本练习是课程的一部分
R 中的特征工程
练习说明
- 在 workflow 中打包模型与配方(recipe)。
- 将 workflow 拟合到训练数据。
- 生成用于性能评估的增强数据框。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Bundle model and recipe in workflow
lr_workflow <- ___() %>%
add_model(lr_model) %>%
add_recipe(lr_recipe)
# Fit workflow to the train data
lr_fit <- ___(lr_workflow, data = train)
# Generate an augmented data frame for performance assessment
lr_aug <- lr_fit %>% ___(test)
lr_aug %>% roc_curve(truth = Attrition, .pred_No) %>% autoplot()
bind_rows(lr_aug %>% roc_auc(truth = Attrition, .pred_No),
lr_aug %>% accuracy(truth = Attrition, .pred_class))