Skip to content

uninformative "outcome should be a factor" error with missing predictors #883

Closed
@mariamaseng

Description

@mariamaseng

Hi! I want to use xgboost for classification but are getting a (simple?) error stating that my outcome variable is not a factor which it indeed is. Is there another better way of making the outcome variable be interpreted as a factor in the model?

All help is much appreciated.

train_test_split = rsample::initial_split(df_num, prop=train_set_prop, strata=kombucha_intake_num)
train = training(train_test_split)
test = testing(train_test_split)
train$kombucha_intake_num =as.factor(train$kombucha_intake_num)
test$kombucha_intake_num = as.factor(test$kombucha_intake_num)

xgb_mod <- 
  boost_tree(trees=50) %>%
  set_engine("xgboost") %>%
  set_mode("classification") %>% 
  fit(kombucha_intake_num ~ ., data=train)`

Error: Error in check_outcome():
! For a classification model, the outcome should be a factor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions