简体   繁体   English

使用 R 中的 tidymodel 框架进行随机森林超参数调整的错误

[英]error in random forest hyperparam tuning using tidymodel framework in R

I am trying to find the right prameter for a random forest regression problem using tidymodels frame work.我正在尝试使用 tidymodels 框架为随机森林回归问题找到合适的参数。

Follwoing is my code:以下是我的代码:

#create recepie on the preped house train data
rf_rec <-
  recipe(log_sale_price ~. , data = house_train_treebased)

#give model spec
rf_mod <-
  rand_forest(mtry = tune(), num.trees = tune()) %>%
  set_engine("ranger")

#create Search grid
rf_grid <- expand.grid(mtry = c(1:30), num.trees = seq(from = 500, to = 1000, by = 100))

#create samples for cross validation
folds <- vfold_cv(house_train_treebased, v = 25)

#create models with grid search
rf_res <-
  tune_grid(rf_rec, model = rf_mod, resamples = folds ,  grid = rf_grid)

I get following errors:我收到以下错误:

> rf_mod <-
+   rand_forest(mtry = tune(), num.trees = tune()) %>%
+   set_engine("ranger")
Error in rand_forest(mtry = tune(), num.trees = tune()) : 
  unused argument (num.trees = tune())
rf_res <-
+   tune_grid(rf_rec, model = rf_mod, resamples = folds ,  grid = rf_grid)
Error: Internal error: `check_installs()` should have caught an `unknown` mode.

What am I missing?我错过了什么?

Assuming your are using theparsnip package, the function call rand_forest has argument trees , but you are specifying an argument num.trees which is not recognized.假设您使用的是parsnip rand_forest ,函数调用rand_forest有参数trees ,但您指定的参数num.trees无法识别。 Try replacing num.trees = tune() with trees = tune() .尝试用num.trees = tune()替换num.trees = tune() trees = tune()

I looked at the github in the following link我在以下链接中查看了github

https://rdrr.io/github/tidymodels/tune/src/R/checks.R https://rdrr.io/github/tidymodels/tune/src/R/checks.R

check_metrics <- function(x, object) {
  mode <- workflows::pull_workflow_spec(object)$mode

  if (is.null(x)) {
    switch(
      mode,
      regression = {
        x <- yardstick::metric_set(rmse, rsq)
      },
      classification = {
        x <- yardstick::metric_set(roc_auc, accuracy)
      },
      unknown = {
        rlang::abort("Internal error: `check_installs()` should have caught an `unknown` mode.")
      },
      rlang::abort("Unknown `mode` for parsnip model.")
    )

    return(x)
  }

I did not provide the mode, ie, if I want a regression or classification.我没有提供模式,即,如果我想要回归或分类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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