誰會留下來?
該練習把多個轉換結合起來並套用到 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)