Building a workflow
With your data ready for analysis, you will declare a logistic_model() to predict whether or not they will arrive late.
You assign the role of "ID" to the flight variable to keep it as a reference for analysis and debugging. From the date variable, you will create new features to explicitly model the effect of holidays and represent factors as dummy variables.
Bundling your model and recipe() together using workflow()will help ensure that subsequent fittings or predictions will implement consistent feature engineering steps.
This exercise is part of the course
Feature Engineering in R
Exercise instructions
- Assign an "ID" role to
flight. - Bundle the model and the recipe into a
workflowobject. - Fit
lr_workflowto thetestdata. - Tidy the fitted workflow.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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(___)