tidymodels / recipes

Pipeable steps for feature engineering and data preprocessing to prepare for modeling
https://recipes.tidymodels.org
Other
571 stars 113 forks source link

Better warn on unseed levels #1326

Closed EmilHvitfeldt closed 5 months ago

EmilHvitfeldt commented 5 months ago

To close #450

library(recipes)

data <- data.frame(a = c(LETTERS, NA))

aaa <- recipe(~ a, data = data) %>%
  step_dummy(a) %>%
  prep()
#> Warning: ! There are new levels in `a`: NA.
#> ℹ Consider using `recipes::step_unknown()` before `step_dummy()` to handle
#>   missing values.

data_train <- tibble(x = c("a", "b"))
data_test <- tibble(x = "c")

rec_spec <- recipe(~., data = data_train) %>%
  step_dummy(x) %>%
  prep()

aaa <- rec_spec %>%
  bake(data_test)
#> Warning: ! There are new levels in `x`: "c".
#> ℹ Consider using `recipes::step_novel()` before `step_dummy()` to handle unseen
#>   values.
EmilHvitfeldt commented 5 months ago

the new snapshots looks worse, but they print neater!

Screenshot 2024-05-30 at 11 33 15 AM

github-actions[bot] commented 5 months ago

This pull request 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.