Hi,
I want to create a function including training based on tidymodels, where I want to allow various options for pre-processing (e.g., scaling or not) and models (e.g., linear regression versus logistic regression). How is this best achieved in code? See some example code below, where I now just comment out certain aspects of the code; but would instead want to make this available for the user within the function.
trainfunction <- function(y, x, na=TRUE, model) {
recipe <-
recipe(y ~ .,
data = dataframe) %>%
recipes::step_BoxCox(all_predictors()) %>%
recipes::step_naomit(V1, skip = TRUE) %>%
#recipes::step_center(all_predictors()) %>%
recipes::step_scale(all_predictors())
model <-
parsnip::linear_reg(penalty = tune(), mixture = tune()) %>%
#parsnip::logistic_reg(mode = "classification", penalty = tune(), mixture = tune()) %>%
parsnip::set_engine("glmnet")
}
...
Thanks in advance