I'm new to workflows (and tidymodels in general), so hopefully the fix is obvious. I'm trying out the null_model interface on the Titanic dataset, adapting this section in the tidymodels docs:
reprex
Preamble:
library(tidyverse)
library(tidymodels)
set.seed(10191)
Load and split:
# train.csv can be found here: https://www.kaggle.com/c/titanic/data
df <- read_csv("train.csv")
split <- initial_split(df, prop=0.8, strata=Survived)
df_train = training(split)
df_test = testing(split)
Convert response variable to a factor:
null_rec <- recipe(Survived ~ ., data=df_train) %>%
step_mutate(Survived=factor(as.logical(Survived)))
Create null model:
null_mod <- null_model(mode="classification") %>%
set_engine("parsnip")
Combine recipe and model into a workflow:
null_wflow <- workflow() %>%
add_recipe(null_rec) %>%
add_model(null_mod)
"Fit" the model:
null_fit <- null_wflow %>%
fit(data=df_train)
Try to make a prediction:
null_pred <- null_fit %>%
predict(df_test, type="prob") %>%
bind_cols(df_test %>% select(Survived))
# Error in factor(as.logical(Survived)) : object 'Survived' not found
I see this error if I replicate the above steps with a logistic regression model as well.
system/package info
- Windows 10
- R: 4.0.0
- RStudio: 1.2.5042
- parsnip: 0.1.1
- recipes: 0.1.12
- tidymodels: 0.1.0
- workflows: 0.1.1
Thanks!