Home > OS >  no applicable method for 'extract_parameter_set_dials' applied to an object of class "
no applicable method for 'extract_parameter_set_dials' applied to an object of class "

Time:04-03

Following the excelent book Tidy modeling with R, Section 14.1, the authors present a case of a SVM model hyperparameter tuning:

library(tidymodels)
tidymodels_prefer()
data(cells, package = "modeldata")
cells <- cells[, -1] # remove case column

svm_rec <- 
  recipe(class ~ ., data = cells) %>%
  step_YeoJohnson(all_numeric_predictors()) %>%
  step_normalize(all_numeric_predictors())

svm_spec <- 
  svm_rbf(cost = tune(), rbf_sigma = tune()) %>% 
  set_engine("kernlab") %>% 
  set_mode("classification")

svm_wflow <- 
  workflow() %>% 
  add_model(svm_spec) %>% 
  add_recipe(svm_rec)

Afterwards, they ilustrate how to change the kernel parameter range, to improve the visualizations of the search:

svm_param <- 
  svm_wflow %>% 
  extract_parameter_set_dials() %>% 
  update(rbf_sigma = rbf_sigma(c(-7, -1)))

But this results in an error:

Error in UseMethod("extract_parameter_set_dials") : 
  no applicable method for 'extract_parameter_set_dials' applied to an object of class "workflow"

Is this due to an update in the tidymodels framework? What woul be the correct way to extract and modify the hyperparameters range?

CodePudding user response:

The packages recently had releases of dials and other packages (like workflows) that added this new generic:

library(tidymodels)
tidymodels_prefer()
data(cells, package = "modeldata")
cells <- cells[, -1] # minus case

svm_rec <- recipe(class ~ ., data = cells) |> 
    step_YeoJohnson(all_numeric_predictors()) |> 
    step_normalize(all_numeric_predictors())

svm_spec <- svm_rbf(cost = tune(), rbf_sigma = tune()) |> 
    set_engine("kernlab") |> 
    set_mode("classification")

svm_wflow <- workflow() |> 
    add_model(svm_spec) |> 
    add_recipe(svm_rec)

svm_wflow |> 
    extract_parameter_set_dials() |>
    update(rbf_sigma = rbf_sigma(c(-7, -1)))
#> Collection of 2 parameters for tuning
#> 
#>  identifier      type    object
#>        cost      cost nparam[ ]
#>   rbf_sigma rbf_sigma nparam[ ]

Created on 2022-04-02 by the reprex package (v2.0.1)

You can read more here, and we recommend updating your packages from CRAN.

  • Related