Hi,
Since I updated the Tidymodels package I get these warnings in my model stacking code that I didn't have before:
warning: No observations were detected in truth
for level: SAC.
Computation will proceed by ignoring those levels.
Any clue on why I have those now and what to do to fix this?
Code:
TE_natal_srba_juv <- TE_natal_srba%>%
filter(Lifestage=="juvenile")%>%
mutate(Origin=factor(Origin),
Ba_Ca = factor(Ba_Ca),
Sr_Ca = factor(Sr_Ca))
split the data to train and testing
split <- initial_split(TE_natal_srba_juv, strata="Origin")
train_d <- training(split)
test_d <- testing(split)
make a set of folds for 10-fold CV
folds_stack <- rsample::vfold_cv(train_d, v = 10)
set the model recipe
recipe <-
recipe(Origin ~ Sr_Ca+Ba_Ca, data = train_d)
step_other(Sr_Ca, Ba_Ca, threshold = .1, other = "other values")
step_novel(Origin)
step_unknown(Origin)# set the performance metrics
metric <- metric_set(accuracy, roc_auc)
set workflow
wflow <-
workflow() %>%
add_recipe(recipe)
set grid for tuning
ctrl_grid <- control_stack_grid()
ctrl_res <- control_stack_resamples()
specify random forest model ---------------------------------------------------
rand_forest_spec <-
rand_forest(
mtry = 2,
min_n = tune(), # let the minimum node to vary
trees = 3000
) %>%
set_mode("classification") %>%
set_engine("ranger")
rand_forest_wflow <-
wflow %>%
add_model(rand_forest_spec)
set.seed(1234)
rand_forest_res <-
tune::tune_grid(
object = rand_forest_wflow,
resamples = folds_stack,
grid = 10,
metrics = metric,
control = ctrl_grid
)