Random and regular grids can be created for any number of parameter objects.
Usage
grid_regular(x, ..., levels = 3, original = TRUE, filter = NULL)
# S3 method for class 'parameters'
grid_regular(x, ..., levels = 3, original = TRUE, filter = NULL)
# S3 method for class 'list'
grid_regular(x, ..., levels = 3, original = TRUE, filter = NULL)
# S3 method for class 'param'
grid_regular(x, ..., levels = 3, original = TRUE, filter = NULL)
grid_random(x, ..., size = 5, original = TRUE, filter = NULL)
# S3 method for class 'parameters'
grid_random(x, ..., size = 5, original = TRUE, filter = NULL)
# S3 method for class 'list'
grid_random(x, ..., size = 5, original = TRUE, filter = NULL)
# S3 method for class 'param'
grid_random(x, ..., size = 5, original = TRUE, filter = NULL)
Arguments
- x
A
param
object, list, orparameters
.- ...
One or more
param
objects (such asmtry()
orpenalty()
). None of the objects can haveunknown()
values in the parameter ranges or values.- levels
An integer for the number of values of each parameter to use to make the regular grid.
levels
can be a single integer or a vector of integers that is the same length as the number of parameters in...
.levels
can be a named integer vector, with names that match the id values of parameters.- original
A logical: should the parameters be in the original units or in the transformed space (if any)?
- filter
A logical: should the parameters be filtered prior to generating the grid. Must be a single expression referencing parameter names that evaluates to a logical vector.
- size
A single integer for the total number of parameter value combinations returned for the random grid. If duplicate combinations are generated from this size, the smaller, unique set is returned.
Details
Note that there may a difference in grids depending on how the function
is called. If the call uses the parameter objects directly the possible
ranges come from the objects in dials
. For example:
mixture()
set.seed(283)
mix_grid_1 <- grid_random(mixture(), size = 1000)
range(mix_grid_1$mixture)
However, in some cases, the parsnip
and recipe
packages overrides
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). Using
the example above, the mixture
argument above is different for
glmnet
models:
Examples
# filter arg will allow you to filter subsequent grid data frame based on some condition.
p <- parameters(penalty(), mixture())
grid_regular(p)
#> # A tibble: 9 × 2
#> penalty mixture
#> <dbl> <dbl>
#> 1 0.0000000001 0
#> 2 0.00001 0
#> 3 1 0
#> 4 0.0000000001 0.5
#> 5 0.00001 0.5
#> 6 1 0.5
#> 7 0.0000000001 1
#> 8 0.00001 1
#> 9 1 1
grid_regular(p, filter = penalty <= .01)
#> # A tibble: 6 × 2
#> penalty mixture
#> <dbl> <dbl>
#> 1 0.0000000001 0
#> 2 0.00001 0
#> 3 0.0000000001 0.5
#> 4 0.00001 0.5
#> 5 0.0000000001 1
#> 6 0.00001 1
# Will fail due to unknowns:
# grid_regular(mtry(), min_n())
grid_regular(penalty(), mixture())
#> # A tibble: 9 × 2
#> penalty mixture
#> <dbl> <dbl>
#> 1 0.0000000001 0
#> 2 0.00001 0
#> 3 1 0
#> 4 0.0000000001 0.5
#> 5 0.00001 0.5
#> 6 1 0.5
#> 7 0.0000000001 1
#> 8 0.00001 1
#> 9 1 1
grid_regular(penalty(), mixture(), levels = 3:4)
#> # A tibble: 12 × 2
#> penalty mixture
#> <dbl> <dbl>
#> 1 0.0000000001 0
#> 2 0.00001 0
#> 3 1 0
#> 4 0.0000000001 0.333
#> 5 0.00001 0.333
#> 6 1 0.333
#> 7 0.0000000001 0.667
#> 8 0.00001 0.667
#> 9 1 0.667
#> 10 0.0000000001 1
#> 11 0.00001 1
#> 12 1 1
grid_regular(penalty(), mixture(), levels = c(mixture = 4, penalty = 3))
#> # A tibble: 12 × 2
#> penalty mixture
#> <dbl> <dbl>
#> 1 0.0000000001 0
#> 2 0.00001 0
#> 3 1 0
#> 4 0.0000000001 0.333
#> 5 0.00001 0.333
#> 6 1 0.333
#> 7 0.0000000001 0.667
#> 8 0.00001 0.667
#> 9 1 0.667
#> 10 0.0000000001 1
#> 11 0.00001 1
#> 12 1 1
grid_random(penalty(), mixture())
#> # A tibble: 5 × 2
#> penalty mixture
#> <dbl> <dbl>
#> 1 0.0000000246 0.490
#> 2 0.000000510 0.985
#> 3 0.000458 0.923
#> 4 0.00202 0.590
#> 5 0.827 0.0951