Box-Cox 轉換
使用包含離職員工所有數值資料的 attrition_num 資料集,你想建立一個模型,利用以 factor 編碼的二元變數 Attrition,來預測某位員工是否可能留下。為了讓特徵更接近常態分布,你將建立一個套用 Box-Cox 轉換的 recipe。
已為你載入 attrition_num 資料、羅吉斯迴歸 lr_model、使用者自訂的 class-evaluate() 函式,以及 train 和 test 的切分。
本練習屬於課程
R 的特徵工程
練習說明
- 建立一個 recipe,使用 Box-Cox 將所有數值型特徵(包含目標變數)轉換。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create a recipe that uses Box-Cox to transform all numeric features
lr_recipe_BC <-
recipe(Attrition ~., data = train) %>%
___(___)
lr_workflow_BC <- workflow() %>%
add_model(lr_model) %>%
add_recipe(lr_recipe_BC)
lr_fit_BC <- lr_workflow_BC %>%
fit(train)
lr_aug_BC <-
lr_fit_BC %>% augment(test)
lr_aug_BC %>% class_evaluate(truth = Attrition,
estimate = .pred_class,.pred_No)