I am building a multilayer perceptron (mlp) model with 2 or 3 hidden layers using the bruleebrulee package within the tidymodelstidymodels framework. How can I wonder how to tune the hyper-parameters including the number of hidden layersnumber of hidden layers, number of hidden_units per layernumber of hidden_units per layer, and penaltypenalty using tune_grid()?
library(tidymodels)
library(brulee)
data(Sacramento, package = "modeldata")
# Data splitting
set.seed(123)
data_split <- initial_split(Sacramento, prop = 0.75, strata = price)
Sac_train <- training(data_split)
Sac_test <- testing(data_split)
# Create the recipe
Sac_recipe <- recipe(price ~ ., data = Sac_train) %>%
step_rm(zip, latitude, longitude) %>%
step_corr(all_numeric_predictors(), threshold = 0.85) %>%
step_normalize(all_numeric_predictors()) %>%
step_dummy(all_nominal_predictors())
A mlp model with 2 hidden layers (each has 30 and 20 hidden units) can be specified below:
# Build the model
mlp_mod <- mlp(hidden_units = c(30, 20), penalty = tune()) %>%
set_engine("brulee", importance = "permutation") %>%
set_mode("regression")
I wonder how to tune the number of hidden layers and number of hidden_units per layer together using tune_grid()? If using hidden_units = tune(), it will only tune the number of hidden_units for a single hidden layer mlp. Thanks.