create_xreg_recipe {modeltime} | R Documentation |
Developer Tools for preparing XREGS (Regressors)
Description
These functions are designed to assist developers in extending the modeltime
package. create_xregs_recipe()
makes it simple to automate conversion
of raw un-encoded features to machine-learning ready features.
Usage
create_xreg_recipe(
data,
prepare = TRUE,
clean_names = TRUE,
dummy_encode = TRUE,
one_hot = FALSE
)
Arguments
data |
A data frame |
prepare |
Whether or not to run |
clean_names |
Uses |
dummy_encode |
Should |
one_hot |
If |
Details
The default recipe contains steps to:
Remove date features
Clean the column names removing spaces and bad characters
Convert ordered factors to regular factors
Convert factors to dummy variables
Remove any variables that have zero variance
Value
A recipe
in either prepared or un-prepared format.
Examples
library(dplyr)
library(timetk)
library(recipes)
library(lubridate)
predictors <- m4_monthly %>%
filter(id == "M750") %>%
select(-value) %>%
mutate(month = month(date, label = TRUE))
predictors
# Create default recipe
xreg_recipe_spec <- create_xreg_recipe(predictors, prepare = TRUE)
# Extracts the preprocessed training data from the recipe (used in your fit function)
juice_xreg_recipe(xreg_recipe_spec)
# Applies the prepared recipe to new data (used in your predict function)
bake_xreg_recipe(xreg_recipe_spec, new_data = predictors)