step_poly()
既然已经有了基线模型,您可以在为所有数值型变量加入多项式变换后,比较模型表现。
attrition_num 数据、逻辑回归模型 lr_model、用户自定义函数 class-evaluate(),以及 train 和 test 切分都已为您加载。
本练习是课程的一部分
R 中的特征工程
练习说明
- 为所有数值型自变量添加多项式变换。
- 将 workflow 拟合到 train 数据。
交互式实操练习
通过完成这段示例代码来试试这个练习。
lr_recipe_poly <-
recipe(Attrition ~., data = train) %>%
# Add a polynomial transformation to all numeric predictors
___
lr_workflow_poly <- workflow() %>%
add_model(lr_model) %>%
add_recipe(lr_recipe_poly)
# Fit workflow to the train data
lr_fit_poly <- ___ %>% fit(train)
lr_aug_poly <- lr_fit_poly %>% augment(test)
lr_aug_poly %>% class_evaluate(truth = Attrition, estimate = .pred_class,.pred_No)