data(biomass, package = "modeldata")
biomass_tr <- biomass[biomass$dataset == "Training", ]
biomass_te <- biomass[biomass$dataset == "Testing", ]
rec <- recipe(
HHV ~ carbon + hydrogen + oxygen + nitrogen + sulfur,
data = biomass_tr
)
norm_trans <- rec %>%
step_normalize(carbon, hydrogen)
norm_obj <- prep(norm_trans, training = biomass_tr)
transformed_te <- bake(norm_obj, biomass_te)
biomass_te[1:10, names(transformed_te)]
transformed_te
tidy(norm_trans, number = 1)
tidy(norm_obj, number = 1)
# To keep the original variables in the output, use `step_mutate_at`:
norm_keep_orig <- rec %>%
step_mutate_at(all_numeric_predictors(), fn = list(orig = ~.)) %>%
step_normalize(-contains("orig"), -all_outcomes())
keep_orig_obj <- prep(norm_keep_orig, training = biomass_tr)
keep_orig_te <- bake(keep_orig_obj, biomass_te)
keep_orig_te
Run the code above in your browser using DataLab