Skip to main content
deleted 143 characters in body
Source Link
TylerH
  • 21.3k
  • 87
  • 85
  • 123

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.

I am building a multilayer perceptron (mlp) model with 2 or 3 hidden layers using the brulee package within the tidymodels framework. I wonder how to tune the hyper-parameters including the number of hidden layers, number of hidden_units per layer, and penalty 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.

I am building a multilayer perceptron (mlp) model with 2 or 3 hidden layers using the brulee package within the tidymodels framework. How can I tune the hyper-parameters including the number of hidden layers, number of hidden_units per layer, and penalty 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")

If using hidden_units = tune(), it will only tune the number of hidden_units for a single hidden layer mlp.

Notice removed Authoritative reference needed by Yang Yang
Bounty Ended with mfg3z0's answer chosen by Yang Yang
Notice added Authoritative reference needed by Yang Yang
Bounty Started worth 50 reputation by Yang Yang
Source Link
Yang Yang
  • 932
  • 4
  • 31
  • 58

How to tune a MLP model with more than 1 hidden layer within the tidymodels framework?

I am building a multilayer perceptron (mlp) model with 2 or 3 hidden layers using the brulee package within the tidymodels framework. I wonder how to tune the hyper-parameters including the number of hidden layers, number of hidden_units per layer, and penalty 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.