ใครจะอยู่ต่อ?
ถึงเวลาฝึกนำการแปลงข้อมูลหลายรูปแบบมาใช้ร่วมกันกับชุดข้อมูล attrition_num โดยเริ่มจากการทำให้ตัวแปรตัวเลขมีการกระจายใกล้เคียงปกติด้วยการแปลง Yeo-Johnson จากนั้นแปลงตัวทำนายที่เป็นตัวเลขให้เป็น percentile สร้าง dummy variable และตัดฟีเจอร์ที่มีความแปรปรวนใกล้ศูนย์ออก
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Feature Engineering in R
คำแนะนำการฝึกหัด
- ใช้การแปลง Yeo-Johnson กับตัวแปรตัวเลขทั้งหมด
- แปลงตัวทำนายที่เป็นตัวเลขทั้งหมดให้เป็น percentile
- สร้าง dummy variable สำหรับตัวทำนายที่เป็น nominal ทั้งหมด
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
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)