'Obtaining the search region of the latin_hypercube grid function
I use tune_grid()
with no parameter grid to tune my hyperparameters (see below, please). According to the help page of the tune_grid()
function, a parameter grid will be created using dials::grid_latin_hypercube()
. I understand (please correct me if I am wrong) that the hypercube function divides the search region into equal subdivisions and randomly picks values from each of these subdivisions. I need to obtain the range of each of these subdivisions. How can I obtain that?
set.seed(345)
Data_RF_fit <-
Data_RF_wflow %>%
tune_grid(val_set,
grid = 25,
control = control_grid(save_pred = TRUE),
metrics = metric_set(rmse))
set.seed(345)
Data_KKNN_fit <-
Data_KKNN_wflow %>%
tune_grid(val_set,
grid = 25,
control = control_grid(save_pred = TRUE),
metrics = metric_set(rmse))
Solution 1:[1]
The function grid_latin_hypercube() creates a grid based on the ranges of the input values that you set. If you don't set any value, it will use the default ranges.
In your case, since I believe you're using k-nearest neighbors, you can check these values using ?nearest_neighbors
to find the tunable hyperparameters. Since these hyperparameters in tidymodels can be ran as commands in the console, you can either check each option by running it as a command, which will output its default state, or check its help page.
So, for example, if you wanted to check the defaults for the neighbors
parameter you could either run
neighbors()
#> # Nearest Neighbors (quantitative)
#> Range: [1, 10]
or
?neighbors
Hope this helps
Solution 2:[2]
You can extract_parameter_set_dials()
from a workflow you have created, and then use that to see the parameter that is created:
library(tidymodels)
knn_spec <-
nearest_neighbor(neighbors = tune()) %>%
set_mode("classification") %>%
set_engine("kknn")
knn_wf <- workflow(Class ~ ., knn_spec)
pset <- extract_parameter_set_dials(knn_wf)
pset$object
#> [[1]]
#> # Nearest Neighbors (quantitative)
#> Range: [1, 15]
## if you need to compute on these:
pset$object[[1]]$range
#> $lower
#> [1] 1
#>
#> $upper
#> [1] 15
Created on 2022-05-18 by the reprex package (v2.0.1)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Nbals |
Solution 2 | Julia Silge |