non-minimal reprex:
The error factor Categorical_Predictor has new levels new comes from model.frame.default() but it is hard to figure that out right now
# Create sample data
library(tidymodels)
set.seed(123)
num_samples <- 100
outcome <- rnorm(num_samples, mean = 50, sd = 10)
categorical_predictor <- as.factor(sample(letters[1:4], num_samples, replace = TRUE))
# Create dataframe
df <- data.frame(
Outcome = outcome,
Categorical_Predictor = categorical_predictor
)
new_row <- data.frame(
Outcome = 55,
Categorical_Predictor = "problem"
)
# Add the new row to the dataframe
df <- rbind(new_row, df)
lr_full_preprocessing <-
recipe(Outcome ~ ., data = df) %>%
# novel categories
step_novel(all_nominal_predictors())
lr_full <- linear_reg() %>%
set_engine("lm")
lr_full_wf <- workflow() %>%
add_recipe(lr_full_preprocessing, blueprint = hardhat::default_recipe_blueprint(allow_novel_levels = FALSE)) %>%
add_model(lr_full)
set.seed(123) # for reproducibility
folds <- vfold_cv(df, v = 2, repeats = 1)
lr_full_fit_rs <- lr_full_wf %>%
fit_resamples(folds)
#> → A | error: factor Categorical_Predictor has new levels new
#> There were issues with some computations A: x1
#> There were issues with some computations A: x1
#>
collect_notes(lr_full_fit_rs) %>%
glimpse()
#> Rows: 1
#> Columns: 4
#> $ id <chr> "Fold1"
#> $ location <chr> "preprocessor 1/1, model 1/1 (predictions)"
#> $ type <chr> "error"
#> $ note <chr> "factor Categorical_Predictor has new levels new"
non-minimal reprex:
The error
factor Categorical_Predictor has new levels newcomes frommodel.frame.default()but it is hard to figure that out right now