merge.recipe: Merge parameter grid values into objects

Description Usage Arguments Value Examples

View source: R/merge.R

Description

merge() can be used to easily update any of the arguments in a parsnip model or recipe.

Usage

1
2
3
4
5
## S3 method for class 'recipe'
merge(x, y, ...)

## S3 method for class 'model_spec'
merge(x, y, ...)

Arguments

x

A recipe or model specification object.

y

A data frame or a parameter grid resulting from one of the grid_* functions. The column names should correspond to the parameter names (or their annotations) in the object.

...

Not used but required for S3 completeness.

Value

A tibble with a column x that has as many rows as were in y.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
library(tibble)
library(recipes)

pca_rec <-
  recipe(mpg ~ ., data = mtcars) %>%
  step_impute_knn(all_predictors(), neighbors = tune()) %>%
  step_pca(all_predictors(), num_comp = tune())

pca_grid <-
  tribble(
    ~neighbors, ~num_comp,
             1,         1,
             5,         1,
             1,         2,
             5,         2
  )

merge(pca_rec, pca_grid)

spline_rec <-
  recipe(mpg ~ ., data = mtcars) %>%
  step_ns(disp, deg_free = tune("disp df")) %>%
  step_ns(wt, deg_free = tune("wt df"))

spline_grid <-
  tribble(
    ~"disp df", ~ "wt df",
    3,         3,
    5,         3,
    3,         5,
    5,         5
  )

merge(pca_rec, pca_grid)

library(parsnip)
library(dials)
data(hpc_data, pacakge = "modeldata")

xgb_mod <-
  boost_tree(trees = tune(), min_n = tune()) %>%
  set_engine("xgboost")

set.seed(254)
xgb_grid <-
  dials::parameters(xgb_mod) %>%
  finalize(hpc_data) %>%
  grid_max_entropy(size = 3)

merge(xgb_mod, xgb_grid)

tune documentation built on July 21, 2021, 5:09 p.m.