简体   繁体   中英

set max depth for tuning ranger in random forest tidymodels r

I would like to tune the depth of my random forest to avoid overfitting. I am using tidymodels and this is my model code.

rf_model <- rand_forest(mtry = tune(), 
                        trees = tune(),
                        max.depth = tune()) %>%
  set_mode("classification") %>%
  set_engine("ranger", importance = "impurity")

It gives me an error that:

Error in rand_forest(mtry = tune(), trees = tune(), max.depth = tune()): unused argument (max.depth = tune())

I also tried tree_depth = tune() from dials documentation, and that gives the same error.

But when I look at ranger documentation, it has max.depth as a parameter. wondering how to tune depth with tidymodels tune.

Thank you

There is no max.depth argument, so like in ranger (see What is equivalent of "max depth" in the 'R' package "ranger"? for explanation) the minimum number of nodes can be used instead. This works:

rf_model <- rand_forest(mtry = tune(), trees = tune(), min_n = tune()) %>%
    set_mode("classification") %>% set_engine("ranger", importance = "impurity")

Which produces a valid rf_model :

> rf_model
Random Forest Model Specification (classification)

Main Arguments:
  mtry = tune()
  trees = tune()
  min_n = tune()

Engine-Specific Arguments:
  importance = impurity

Computational engine: ranger 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM