tidymodels/embed

`woe_table()` does not respect factor levels

Closed this issue · 1 comments

This SO question highlights a bug in step_woe(), where the use of unique() here strips away the order of factor levels:

embed/R/woe.R

Line 175 in fab0e9c

outcome_original_labels <- unique(outcome)

Notice that we get the same output no matter the order of the factors levels:

labels <- sample(c("yes", "no"), 20, replace = TRUE)

unique(factor(labels, levels = c("yes", "no")))
#> [1] yes no 
#> Levels: yes no
unique(factor(labels, levels = c("no", "yes")))
#> [1] yes no 
#> Levels: no yes

Created on 2022-02-23 by the reprex package (v2.0.1)

Could we use levels() there instead?

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.