開始使用免費開始

前處理

進入特徵工程時間!你需要建立一個 recipe,處理像觀測 ID 這類沒有資訊量但可能有用的變數,或是處理遺漏值。這同時也是轉換部分預測變數的好機會;例如,將數值型特徵標準化,並為類別型特徵建立虛擬變數。

你在前一個練習建立的 attrition 資料集,以及 traintest 切分,已經在你的環境中可用。

本練習屬於課程

R 的特徵工程

檢視課程

練習說明

  • 標準化所有數值型特徵。
  • 使用 knn 插補演算法來填補遺漏值。
  • 為所有名目型預測變數建立虛擬變數。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

recipe <- recipe(Attrition ~ ., data = train) %>%
  update_role(...1, new_role = "ID") %>%

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

# Impute missing values using the knn imputation algorithm
  ___(all_predictors()) %>%

# Create dummy variables for all nominal predictors
  ___(all_nominal_predictors())
 
recipe
編輯並執行程式碼