R 中的特征工程
Jorge Zazueta
Research Professor. Head of the Modeling Group at the School of Economics, UASLP
更完整的模型包含更多变量。
lr_model <- logistic_reg()
lr_recipe <-
recipe(class~ sponsor_code +
contract_value_band +
category_code,
data = grants_train) %>%
step_lencode_glm(sponsor_code,
contract_value_band,
category_code,
outcome = vars(class))
结果更具说服力。
lr_aug %>% class_evaluate(truth = class,
estimate = .pred_class,
.pred_successful)
# A tibble: 2 × 3
.metric .estimator .estimate
<chr> <chr> <dbl>
1 accuracy binary 0.890
2 roc_auc binary 0.951
可使用 vip() 包绘制按重要性排序的特征。
lr_fit %>%
extract_fit_parsnip() %>%
vip(aesthetics =
list(fill = "steelblue"))
变量重要性图

变量重要性可作为强有力的反馈,用于结合领域知识改进特征工程。

R 中的特征工程