Hi,
I try to tune a random forest with tidymodels, but end up with this error message (for all folds):
Bootstrap01: preprocessor 1/1, model 1/27: Error in y.mat[, 2]: subscript out of bounds
This is my code:
# Random Forest -----------------------------------------------------------
set.seed(123)
split <- initial_split(image, strata = "nps_brand")
train <- training(split)
test <- testing(split)
set.seed(234)
folds <- bootstraps(train, strata = "nps_brand")
# Define Recipe -----------------------------------------------------------
rf_recipe <- recipe(nps_brand ~ ., data = train) %>%
step_dummy(nps_brand)
# Define Model Spec -------------------------------------------------------
rf_model <- rand_forest(
mtry = tune(),
trees = tune(),
min_n = tune()) %>%
set_mode("classification") %>%
set_engine("ranger")
# Define Workflow ---------------------------------------------------------
rf_workflow <- workflow() %>%
add_recipe(rf_recipe) %>%
add_model(rf_model)
# Define Grid -------------------------------------------------------------
rf_grid <- grid_regular(min_n(),
trees(),
mtry(range(1,floor(sqrt(ncol(train)-1)))))
# Tuning ------------------------------------------------------------------
set.seed(123)
rf_trained <- tune_grid(rf_workflow,
resamples = folds,
grid = rf_grid,
metrics = metric_set(accuracy, roc_auc),
control = control_grid(verbose = TRUE))
I tried to find out, what might be wrong but can't find a solution and would appreciate help.
Best Chris