r-调整配方参数的潮汐模型



使用tidymodels,我真的很喜欢不仅调整模型参数,还调整一些配方步骤的可能性。例如,step_pls((中的组件数。问题是,我在限制可能值的范围方面遇到了麻烦。例如,如果我想使用step_umap,我想将搜索空间限制为2:5个组件。当我用step_umap((替换step_pls((时,下面的代码会导致会话崩溃。它试图用大约50个组件构建umap。。。因此,基本上,我的问题是,在使用grid_arandom或grid_max_entropy时,如何限制特定调优参数的搜索范围?

注意:也尝试了类似param_grid%>%grid_random(size=5,num_comp() %>% range_set(c(3, 5)))的东西。但似乎被忽视了。

感谢

# 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))

如果你想试用num_comp的特定范围,我不会去工作流和获取参数等。我会直接用参数设置调整网格:

library(dials)
#> Loading required package: scales
grid_max_entropy(penalty(),
mixture(),
num_comp(range = c(2, 5)),
size = 5)
#> # A tibble: 5 x 3
#>         penalty mixture num_comp
#>           <dbl>   <dbl>    <int>
#> 1 0.00161        0.721         5
#> 2 0.751          0.376         4
#> 3 0.00000000974  0.395         3
#> 4 0.000107       0.0747        4
#> 5 0.0000000451   0.906         3

创建于2020-07-19由reprex包(v0.3.0(

相关内容

  • 没有找到相关文章

最新更新