การสร้าง Workflow
เมื่อข้อมูลพร้อมสำหรับการวิเคราะห์แล้ว ให้ประกาศ logistic_model() เพื่อพยากรณ์ว่าเที่ยวบินจะมาสายหรือไม่
กำหนดบทบาทเป็น "ID" ให้กับตัวแปร flight เพื่อใช้เป็นตัวอ้างอิงสำหรับการวิเคราะห์และการดีบัก จากตัวแปร date จะสร้าง feature ใหม่เพื่อจำลองผลกระทบของวันหยุด และแปลง factors เป็น dummy variables
การรวม โมเดล และ recipe() เข้าด้วยกันโดยใช้ workflow() จะช่วยให้มั่นใจได้ว่าการ fit หรือการพยากรณ์ในขั้นตอนถัดไปจะใช้ขั้นตอน feature engineering ที่สอดคล้องกันเสมอ
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Feature Engineering in R
คำแนะนำการฝึกหัด
- กำหนดบทบาทเป็น "ID" ให้กับ
flight - รวมโมเดลและ recipe เข้าเป็น object
workflow - Fit
lr_workflowกับข้อมูลtest - Tidy workflow ที่ fit แล้ว
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
lr_model <- logistic_reg()
# Assign an "ID" role to flight
lr_recipe <- recipe(arrival ~., data = train) %>% update_role(flight, new_role = ___) %>%
step_holiday(date, holidays = timeDate::listHolidays("US")) %>% step_dummy(all_nominal_predictors())
# Bundle the model and the recipe into a workflow object
lr_workflow <- workflow() %>% add_model(___) %>% add_recipe(___)
lr_workflow
# Fit lr_workflow workflow to the test data
lr_fit <- lr_workflow %>% ___(data = test)
# Tidy the fitted workflow
tidy(___)