谁会留下来?
现在来练习在 attrition_num 数据上组合多种变换。首先,对数值变量应用 Yeo-Johnson 变换,使其标准化或近似正态化。接着,将数值型自变量转换为分位数,创建哑变量,并删除方差接近于零的特征。
本练习是课程的一部分
R 中的特征工程
练习说明
- 对所有数值变量应用 Yeo-Johnson 变换。
- 将所有数值型自变量转换为分位数。
- 为所有名义型自变量创建哑变量。
交互式实操练习
通过完成这段示例代码来试试这个练习。
lr_recipe <- recipe(Attrition ~., data = train) %>%
# Apply a Yeo-Johnson transformation to all numeric variables
___ %>%
# Transform all numeric predictors into percentiles
___ %>%
# Create dummy variables for all nominal predictors
___
lr_workflow <- workflow() %>% add_model(lr_model) %>% add_recipe(lr_recipe)
lr_fit <- lr_workflow %>% fit(train)
lr_aug <- lr_fit %>% augment(test)
lr_aug %>% class_evaluate(truth = Attrition, estimate = .pred_class,.pred_No)