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

Error: 'train_catboost' is not an exported object from 'namespace:treesnip #68

Open angelhsu05 opened 1 year ago

angelhsu05 commented 1 year ago

I'm trying to conduct a grid search per https://www.r-bloggers.com/2020/08/how-to-use-catboost-with-tidymodels/, but when I try, following this example, i'm getting an error where all models fail and it says "train_catboost" is not an exported object from 'namespace:treesnip'

vidarvr commented 8 months ago

For anyone having similar problems there are two solutions that worked for me, both on windows and linux (docker).

When running sequentially it's should be sufficienet to add this to my code:

parsnip::set_dependency("boost_tree", eng = "catboost", pkg = "catboost", mode = "regression")
parsnip::set_dependency("boost_tree", eng = "catboost", pkg = "treesnip", mode = "regression")

However, when I tune the hyperparameters (grid search or a race method) and use parallel processing I still get an error.

This is what worked for me:

    cl <- parallel::makeCluster(n_cores)

    result <- parallel::clusterEvalQ(cl, {
      sink(file=NULL)
      library(tidymodels)
      library(catboost)
      library(treesnip)
      sink()
    })

    doParallel::registerDoParallel(cl)