if (FALSE) { # rlang::is_installed(c("modeldata", "ggplot2", "kernlab"))
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
)
kpca_trans <- rec %>%
step_YeoJohnson(all_numeric_predictors()) %>%
step_normalize(all_numeric_predictors()) %>%
step_kpca(all_numeric_predictors())
if (require(kernlab) & require(ggplot2)) {
kpca_estimates <- prep(kpca_trans, training = biomass_tr)
kpca_te <- bake(kpca_estimates, biomass_te)
ggplot(kpca_te, aes(x = kPC1, y = kPC2)) +
geom_point() +
coord_equal()
tidy(kpca_trans, number = 3)
tidy(kpca_estimates, number = 3)
}
}
Run the code above in your browser using DataLab