筛选变量重要性
attrition 数据集包含 839 条观测和 30 个用于预测 "Attrition" 的自变量。您想比较两种模型的权衡:一种使用所有可用自变量,另一种仅基于少量信息量较高的变量的精简模型。
在本练习中,您将先拟合一个模型,并查看该拟合模型的变量重要性。在下一个练习中,您将用这个模型与一个精简模型进行比较,以评估模型性能。
您的环境中已提供 train 与 test 数据切分、vip() 包,以及预先声明的逻辑回归 model。
本练习是课程的一部分
R 中的特征工程
练习说明
- 创建一个使用所有自变量来建模
Attrition的 recipe。 - 将工作流拟合到训练数据。
- 使用
fit_full对象绘制模型的变量重要性。 - 在调用
vip()之前使用extract_fit_parsnip(),以提供所需的信息。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create a recipe that models Attrition using all the predictors
recipe_full <- ___(___, data = train)
workflow_full <- workflow() %>%
add_model(model) %>%
add_recipe(recipe_full)
# Fit the workflow to the training data
fit_full <- ___ %>%
___(data = train)
# Use the fit_full object to graph the variable importance of your model. Apply extract_fit_parsnip() function before vip()
fit_full %>% ___() %>%
___(aesthetics = list(fill = "steelblue"))