stacked model error in tidymodels

Hi,

I have build one stacked model for multinomial classification using tidmodels with following code. However, one errow was arised. Is anyone can help me? It's seen that came from the LDA model.

Best,
Pinjun

Error:
Problem with mutate() column idx.
i idx = which.max(dplyr::c_across(dplyr::starts_with(".pred_"))).
i idx must be size 1, not 0.
i Did you mean: idx = list(which.max(dplyr::c_across(dplyr::starts_with(".pred_")))) ?
i The error occurred in row 3.
Caused by error in abort_glue():

registerDoParallel(4)

recipe_origin <- iris_training %>%
recipe(Score ~ . ) %>%
step_rm(Variety, BPH, Days, Position, Resolution, Cover, Pot, Replicate)

k_cv <- vfold_cv(iris_training, v = 5, repeats = 5)

ctrl_grid <- control_grid(extract = identity, save_pred = TRUE,
parallel_over = "everything",
save_workflow = TRUE)

svm_model <-
svm_rbf(
cost = tune(),
rbf_sigma = tune()
) %>%
set_mode("classification") %>%
set_engine("kernlab") %>%

lmda_reg_model <-
discrim_linear(penalty = tune()) %>% #?discrim_flexible, discrim_regularized
set_engine("mda") %>%
set_mode("classification") %>%

chi_models <-
workflow_set(
preproc = list(simple = iris_recipe_origin),
models = listsvm_model = svm_model, lmda = lmda_reg_model),
cross = TRUE
)

chi_models_res <-
chi_models %>%
workflow_map("tune_grid", resamples = k_cv,
metrics = metric_set(roc_auc, accuracy), verbose = TRUE, seed = 123,
control = ctrl_grid)

grid_ens <- stacks() %>%
add_candidates(chi_models_res)

#Determine stacking coefficients
grid_fit <- blend_predictions(grid_ens)

#Fit model tack members with non-zero stacking coefficients
grid_members <- fit_members(grid_fit)

stack_res <- iris_testing %>% bind_cols(predict(grid_members, ., type = "prob"))

sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7600)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936
[2] LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.936

attached base packages:
[1] parallel stats graphics grDevices utils datasets
[7] methods base

other attached packages:
[1] prospectr_0.2.1 keras_2.7.0.9000
[3] doParallel_1.0.16 iterators_1.0.13
[5] multilevelmod_0.0.0.9000 naivebayes_0.9.7
[7] discrim_0.1.2 stacks_0.2.0
[9] plsmod_0.1.1 themis_0.1.4.9000
[11] recipeselectors_0.0.1 pacman_0.5.1
[13] yardstick_0.0.8.9000 workflowsets_0.1.0.9000
[15] workflows_0.2.4 tune_0.1.6
[17] rsample_0.1.0 recipes_0.1.17
[19] parsnip_0.1.7 modeldata_0.1.1
[21] infer_1.0.0 dials_0.0.10
[23] scales_1.1.1.9000 broom_0.7.9
[25] tidymodels_0.1.4.9000 forcats_0.5.1
[27] stringr_1.4.0 dplyr_1.0.7
[29] purrr_0.3.4 readr_2.0.2
[31] tidyr_1.1.4 tibble_3.1.5
[33] ggplot2_3.3.5 tidyverse_1.3.1.9000
[35] doFuture_0.12.0 future_1.22.1
[37] foreach_1.5.1

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.