Using tidymodels, I really love the possibility of tuning not only model parameters, but also some recipes steps. For example the number of components in step_pls(). The issue is that I'm finding trouble in limiting the range of possible values. For example, if I want to use step_umap I would like to limit the search space to 2:5 components. When I replace step_pls() by step_umap(), the following code causes the session to crash. It tries to build umap with around 50 components...
So basically, my question is, while using grid_random or grid_max_entropy, how can I limit the range of search for a specific tuning parameter?
Note: also tried something like param_grid%>%grid_random(size=5,num_comp() %>% range_set(c(3, 5)))
. But seems to be ignored.
Thanks
# Load Packages -----------------------------------------------------------
require(tidyverse)
require(lubridate)
require(tidymodels)
require(rsample)
require(themis)
require(recipes)
require(embed)
# Load Data ---------------------------------------------------------------
data<-read_csv("....data.csv")
# Modelling - Data Partition ----------------------------------------------
split_prop <- 0.80
init_split <- initial_time_split(data, prop = split_prop)
set_train<-training(init_split)
set_test<-testing(init_split)
# Modelling - Resamples ---------------------------------------------------
valid_folds <- rsample::vfold_cv(set_train,v=5)
# Modelling - Data Transf -------------------------------------------------
recip_train <- recipe(label ~ .,
data = set_train)%>%
step_normalize(all_predictors())%>%
step_pls(all_predictors(),outcome = "label",num_comp = tune())
# Modelling - Model Specs ---------------------------------------------------
model_glm <- linear_reg()%>%
set_args(penalty=tune(),
mixture=tune())%>%
set_mode("regression") %>%
set_engine("glmnet")
# Workflow ------------------------------------------------------------------
wflw <- workflow() %>%
add_recipe(recip_train) %>%
add_model(model_glm)
# Modelling - Tuning Control -------------------------------------------------
ctr_tune <- control_grid(
verbose = TRUE,
allow_par = TRUE,
extract = NULL,
save_pred = TRUE,
pkgs = NULL
)
param_grid<-wflw %>%
parameters()%>%
finalize(set_train)%>%
grid_max_entropy(size = 5)
# Modelling - Tuning ---------------------------------------------------------
tuning <- tune_grid(object = wflw,
resamples = valid_folds,
grid = param_grid,
control = ctr_tune,
metrics = metric_set(rmse))
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…