开始使用免费开始使用

标准化与对数变换

给您一个数据集 attrition_num,其中包含离职员工的数值型数据。特征包括 AgeDistanceFromHomeMonthlyRate

您希望用这些数据构建一个模型,用来预测员工是否可能留下,标签为 Attrition,这是用 factor 编码的二元变量。为建模做准备时,您希望降低可能的偏度,并防止某些变量由于量纲不同而对结果影响过大。

attrition_num 数据以及 traintest 划分已为您加载。

本练习是课程的一部分

R 中的特征工程

查看课程

练习说明

  • 标准化所有数值型自变量。
  • 对所有数值型特征进行对数变换,并使用 1 作为偏移量。

交互式实操练习

通过完成这段示例代码来试试这个练习。

lr_model <- logistic_reg()

lr_recipe <- 
  recipe(Attrition~., data = train) %>%

# Normalize all numeric predictors
  ___(all_numeric_predictors()) %>%

# Log-transform all numeric features, with an offset of one
  ___(___, offset = ___)

lr_workflow <- 
  workflow() %>%
  add_model(lr_model) %>%
  add_recipe(lr_recipe)

lr_workflow
编辑并运行代码