'How do space-filling parameter grids change when we call them by parsnip and recipe packages?

According to this (https://dials.tidymodels.org/reference/grid_max_entropy.html) page, the output of a grid function may vary depending on whether we use a parameter object produced by parsnip and recipes, or we directly use a parameter object. However, it is not clear how one can obtain the parameter range if we use parameters object created from a model or recipe. For example, the default range of neighbors() is [1, 10]. When I use

myGrid <- grid_latin_hypercube(extract_parameter_set_dials(x), size = 25)

where x is a model, and obtain the range using

range(myGrid$neighbors)

I get some values for my neighbors that fall outside [1,10]. How can I obtain the default range of neighbors when I use a parameters object created from a model or recipe?



Solution 1:[1]

As you saw in the documentation:

the parsnip and recipe packages may override the default ranges for specific models and preprocessing steps. If the grid function uses a parameters object created from a model or recipe, the ranges may have different defaults (specific to those models)

You can see the ranges by looking at the object element of the parameter set object.

library(tidymodels)

knn_spec <- nearest_neighbor(neighbors = tune())

extract_parameter_set_dials(knn_spec)$object
#> [[1]]
#> # Nearest Neighbors (quantitative)
#> Range: [1, 15]

Created on 2022-05-13 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 EmilHvitfeldt