during a model creation with R and tidymodels
, as I'm using bootstrap validation as training strategy, I've found that sometimes tune_grid()
function returns this error:
! Bootstrap01: recipe 2/3, model 4/10 (predictions): There are new
levels in a factor: ...
I understand that this is due to some factor levels missing between train and validation subset. I also know that this probably means that should be better to collapse low frequency levels.
However I've just wondering if could be possible force to pre-create dummy variables from a list of levels. At the moment I've tried with:
step_string2factor(my_factor_variable, levels = list("A","B","C") )
or
step_dummy(my_factor_variable,levels = levels = list("A","B","C") )
But without luck. Any suggestion?