在 tidymodels 中调整 catboost 时与标签相关的错误

Error related to labels when tuning catboost in tidymodels

这是模型:

cb_spec <- boost_tree(
  mode = "classification",
  trees = 1000,
  tree_depth = tune(),
  min_n = tune(),
  mtry = tune(),
  learn_rate = tune()
) %>%
  set_engine("catboost", loss_function = "Logloss", task_type = "GPU")

这是食谱:

cb_rec <- recipe(covid_vaccination ~ ., data = cb_train) %>% 
  step_unknown(all_nominal_predictors()) %>%
  #step_dummy(all_nominal_predictors(), one_hot = TRUE) %>%
  step_impute_median(all_numeric_predictors()) %>% 
  step_nzv(all_predictors())

我把它们结合起来:

cb_wf <- workflow() %>% 
  add_model(cb_spec) %>% 
  add_recipe(cb_rec)

然后我尝试调整以找到最佳超参数:

cb_tune <- tune_grid(
  object = cb_wf,
  resamples = cb_folds,
  grid = cb_grid,
  metrics = metric_set(roc_auc),
  control = control_grid(verbose = TRUE)
)

这是我得到的错误:

Error in catboost.from_matrix(as.matrix(float_and_cat_features_data), : Unsupported label type, expecting double or integer.

我已经确认分类变量已更改为因子。我的数据集中绝对没有字符类型向量。

https://github.com/catboost/catboost/issues/1874

多亏了一个很棒的人,他自己制作了 treesnip 的分支作为解决方法:Mikhail Rudakov