curso-r / treesnip

Parsnip backends for `tree`, `lightGBM` and `Catboost`
https://curso-r.github.io/treesnip
GNU General Public License v3.0
85 stars 13 forks source link

sample_size does not work for Catboost #49

Open vidarsumo opened 2 years ago

vidarsumo commented 2 years ago

I'm trying to tune sample_size for Catboost but it gives an error:

library(modeltime)
library(treesnip)
#> Loading required package: parsnip
library(tidyverse)
library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#>   method                   from   
#>   required_pkgs.model_spec parsnip
library(timetk)

library(catboost)

m750_lag <- m750 %>%
    tk_augment_lags(value, .lags = 1:2)

resamples_kfold <- vfold_cv(m750_lag, v = 3)

recipe_spec <- recipe(value ~ ., data = m750_lag) %>%
    update_role(date, new_role = "indicator")

model_spec_catboost <- boost_tree(
    mode           = "regression",
    trees          = tune(),
    min_n          = tune(),
    tree_depth     = tune(),
    learn_rate     = tune(),
    sample_size    = tune()
    ) %>%
    set_engine("catboost")

wflw_catboost <- workflow() %>%
    add_model(model_spec_catboost) %>%
    add_recipe(recipe_spec)

grid_latin_hypercube(wflw_catboost)
#> # A tibble: 3 x 4
#>   trees min_n tree_depth    learn_rate
#>   <int> <int>      <int>         <dbl>
#> 1   315    22          5 0.0188       
#> 2  1245     4         13 0.00000000648
#> 3  1421    34          8 0.0000360
catboost_tuned <- tune_grid(
    object     = wflw_catboost,
    resamples  = resamples_kfold,
    param_info = parameters(wflw_catboost) %>%
        update(sample_size = sample_prop(range = c(0, 1))),
    grid = 3,
    control = control_grid(verbose = TRUE)
    )
#> Error: At least one parameter does not match any id's in the set: 'sample_size'

Created on 2021-09-11 by the reprex package (v2.0.1)

p-schaefer commented 2 years ago

I came across this issue as well, I wonder if its related to #22 because it seems to affect lightgbm as well.