Tuning Multiple Parameters in a model with the same name

Hi,

I have the below code where i have three attributes i am trying to tune. They are all called the same thing. Does anyone know how i would fit them into tuning grid?

For example the tuning paramter for PCA, correlation and bucketing of character attributes is called threshold. I would like to somehow identify each tuning parameter associated with each attribute.

Below is the psuedocode

library(tidymodels)
library(tidyverse)
library(modeldata)

data("attrition")
mod_data <- attrition

att_rec <- 
  recipe(Attrition ~ ., data = mod_data) %>%
  step_other(all_nominal_predictors(), threshold = tune()) %>% 
  step_unknown(all_nominal_predictors()) %>% 
  step_dummy(all_nominal_predictors(), one_hot = TRUE) %>%
  step_zv(all_predictors()) %>% 
  step_corr(all_numeric_predictors(), threshold = tune()) %>% 
  step_pca(all_numeric_predictors(), threshold = tune())

lasso_spec <- linear_reg(penalty = tune(), mixture = 1) %>%
  set_engine("glmnet")

lambda_grid <- grid_regular(penalty(),
                            threshold() # but we have three thresholds so how do we set them
                            levels = 50)

# Add to the workflow and run.......

Any help would be greatly appreciated.

Thank you for your time

Hi,

The below code should do it, I think

att_rec <- 
  recipe(Attrition ~ ., data = mod_data) %>%
  step_other(all_nominal_predictors(),  threshold = tune('other_threshold')) %>% 
  step_unknown(all_nominal_predictors()) %>% 
  step_dummy(all_nominal_predictors(), one_hot = TRUE) %>%
  step_zv(all_predictors()) %>% 
  step_corr(all_numeric_predictors(),  threshold = tune('corr_threshold')) %>% 
  step_pca(all_numeric_predictors(),  threshold = tune('pca_threshold'))

recipes_param <- parameters(att_rec)
Collection of 3 parameters for tuning

# identifier      type    object
# other_threshold threshold nparam[+]
# corr_threshold threshold nparam[+]
# pca_threshold threshold nparam[+]

lasso_mod <- logistic_reg(penalty = tune(), mixture = 1) %>%
  set_engine("glmnet")

# Here we update them
wflow_grid <- 
  workflow() %>% 
  add_recipe(att_rec) %>% 
  add_model(lasso_spec) %>% 
  grid_max_entropy(size = 20) 


1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.