Closed datalorax closed 4 years ago
You are correct there is a mistake in the documentation. version 0.0.3 changes all parameter objects to functions. Thus you need to use trees()
instead of trees
.
Thus your example will be:
library(tidymodels)
#> Registered S3 method overwritten by 'xts':
#> method from
#> as.zoo.xts zoo
#> ── Attaching packages ───────────────────────────────────────────── tidymodels 0.0.3 ──
#> ✓ broom 0.5.2 ✓ purrr 0.3.3
#> ✓ dials 0.0.4 ✓ recipes 0.1.7.9001
#> ✓ dplyr 0.8.3 ✓ rsample 0.0.5
#> ✓ ggplot2 3.2.1 ✓ tibble 2.1.3
#> ✓ infer 0.5.1 ✓ yardstick 0.0.4
#> ✓ parsnip 0.0.4
#> ── Conflicts ──────────────────────────────────────────────── tidymodels_conflicts() ──
#> x purrr::discard() masks scales::discard()
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag() masks stats::lag()
#> x ggplot2::margin() masks dials::margin()
#> x recipes::step() masks stats::step()
#> x recipes::yj_trans() masks scales::yj_trans()
library(dials)
set.seed(1263)
bst_grid <- grid_random(
trees() %>% range_set(c( 1, 50)),
min_n() %>% range_set(c( 2, 30)),
sample_size() %>% range_set(c(20, 130)),
size = 3
)
bst_grid
#> # A tibble: 3 x 3
#> trees min_n sample_size
#> <int> <int> <int>
#> 1 23 23 110
#> 2 11 18 26
#> 3 14 12 116
Created on 2019-12-16 by the reprex package (v0.3.0)
Ah... perfect. Thanks!
Sorry to follow up here again, but I'm still not able to get the rest of this documentation to run. Specifically, the merge still doesn't seem to work
library(tidymodels)
mod_obj <- boost_tree(mode = "classification",
trees = 50,
min_n = varying(),
sample_size = 3/4)
set.seed(1263)
bst_grid <- grid_random(
trees() %>% range_set(c( 1, 50)),
min_n() %>% range_set(c( 2, 30)),
sample_size() %>% range_set(c(20, 130)),
size = 3
)
for(i in 1:nrow(bst_grid)) {
print(merge(mod_obj, bst_grid[i, ]))
}
#> Error in as.data.frame.default(x): cannot coerce class 'c("boost_tree", "model_spec")' to a data.frame
Created on 2019-12-16 by the reprex package (v0.3.0)
tune
is about to be released so you would use tune()
instead of varying()
. I'll update the docs once that is released (hopefully next week).
You will also need to set the engine for merge()
to work.
library(tidymodels)
#> Registered S3 method overwritten by 'xts':
#> method from
#> as.zoo.xts zoo
#> ── Attaching packages ───────────────────────────────────────────────────────────────────────────── tidymodels 0.0.3 ──
#> ✓ broom 0.5.2 ✓ purrr 0.3.3
#> ✓ dials 0.0.4 ✓ recipes 0.1.8
#> ✓ dplyr 0.8.3 ✓ rsample 0.0.5
#> ✓ ggplot2 3.2.1 ✓ tibble 2.1.3
#> ✓ infer 0.5.1 ✓ yardstick 0.0.4
#> ✓ parsnip 0.0.4
#> ── Conflicts ──────────────────────────────────────────────────────────────────────────────── tidymodels_conflicts() ──
#> x purrr::discard() masks scales::discard()
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag() masks stats::lag()
#> x ggplot2::margin() masks dials::margin()
#> x recipes::step() masks stats::step()
#> x recipes::yj_trans() masks scales::yj_trans()
library(tune)
mod_obj <-
boost_tree(mode = "classification",
trees = 50,
min_n = tune(),
sample_size = 3/4) %>%
set_engine("xgboost")
set.seed(1263)
bst_grid <- grid_random(
trees() %>% range_set(c( 1, 50)),
min_n() %>% range_set(c( 2, 30)),
sample_size() %>% range_set(c(20, 130)),
size = 3
)
bst_grid
#> # A tibble: 3 x 3
#> trees min_n sample_size
#> <int> <int> <int>
#> 1 23 23 110
#> 2 11 18 26
#> 3 14 12 116
# only updates the unknown parameters (not trees here)
for(i in 1:nrow(bst_grid)) {
print(merge(mod_obj, bst_grid[i, ]))
}
#> # A tibble: 1 x 1
#> x
#> * <list>
#> 1 <spec[+]>
#> # A tibble: 1 x 1
#> x
#> * <list>
#> 1 <spec[+]>
#> # A tibble: 1 x 1
#> x
#> * <list>
#> 1 <spec[+]>
merge(mod_obj, bst_grid[1, ])$x
#> [[1]]
#> Boosted Tree Model Specification (classification)
#>
#> Main Arguments:
#> trees = 50
#> min_n = 23
#> sample_size = 3/4
#>
#> Computational engine: xgboost
# also, in tune:
finalize_model(mod_obj, bst_grid[1, ])
#> Boosted Tree Model Specification (classification)
#>
#> Main Arguments:
#> trees = 50
#> min_n = 23
#> sample_size = 3/4
#>
#> Computational engine: xgboost
Created on 2020-01-06 by the reprex package (v0.3.0)
Great, thanks!
Is merge working from 'base::merge' or a dials function of merge that isn't available to the outside? I still am getting the cannot_coerce message because it's attempting to use the base merge data.frame function.
dials package does not seem to have any merge function. I have checked in tune also. Without merge, rest of the example does not seem to work. Is there any alternative or work-around for merge function?
There are merge methods in tune
:
library(tune)
methods("merge")
#> [1] merge.data.frame merge.default merge.dendrogram* merge.estimate*
#> [5] merge.glm* merge.lm* merge.lvm* merge.lvmfit*
#> [9] merge.model_spec* merge.multinomial* merge.recipe*
#> see '?methods' for accessing help and source code
Created on 2020-04-03 by the reprex package (v0.3.0)
I suggest opening another issue and giving a reprex for what you want to do.
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.
Hi,
Perhaps I'm missing something, but I am unable to get the example from the documentation here to work. Reprex below. I do have the dev versions of
dplyr
andggplot2
, as you can see, so perhaps there's something there that's interfering?Created on 2019-12-16 by the reprex package (v0.3.0)