開始使用免費開始

正規化與對數轉換

你拿到一個資料集 attrition_num,其中包含離職員工的數值型資料。特徵包含 AgeDistanceFromHomeMonthlyRate

你想用這些資料來建立一個模型,用以預測員工是否可能留下,這由 Attrition 表示,為以 factor 編碼的二元變數。為了建模前的準備,你想降低可能的偏態,並避免因尺度差異而使部分變數影響力過大。

attrition_num 資料,以及 traintest 切分都已為你載入。

本練習屬於課程

R 的特徵工程

檢視課程

練習說明

  • 將所有數值型預測變數做正規化。
  • 將所有數值型特徵做對數轉換,並設定 offset 為 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
編輯並執行程式碼