Unable to predict using tidymodels (hardhat::forge error)

I'm unable to run the predict function on my fit object.

Here is my r code :

#load libraries

#using mtcars as example
thisdf <- mtcars
response.var <- 'mpg'

#eliminate non-numeric columns
thisdf2 <- thisdf %>%

#eliminate rows with missing response variables
thisdf2 <- thisdf2[!is.na(thisdf2[,response.var]),]

#train test split
thisdf2.split <- initial_split(thisdf2, prop=0.6)
thisdf2.train <- training (thisdf2.split)
thisdf2.test  <- testing  (thisdf2.split)

f <- as.formula(paste0(response.var, ' ~ .'))

#5 fold cross validation
thisdf.cv <- vfold_cv(thisdf2.train, v=5)

this.recipe   <-    recipe(f, data=thisdf2.train) %>%
  step_corr(all_predictors()) %>%
  step_nzv(all_predictors()) %>%
  step_medianimpute(all_predictors()) %>%
  step_center(all_predictors()) %>%

this.model <- rand_forest(mode='regression') %>%  #,mtry=tune(), trees=tune()
  set_engine("ranger", importance='impurity')

this.wf <- workflow() %>%
  add_model(this.model) %>%
train.wf <- this.wf %>%

#measure performance
thisdf2.test$preds <- predict(train.wf, newdata = thisdf2.test) 

The predict call throws the following error :

I tried using skip=TRUE argument for the recipe arguments but still get the error.

Found the resolution.
Works if I simply not use newdata argument.
predict(train.wf, thisdf2.test) works correctly.

I'm new to tidymodels and newdata argument is standard arg for predict functions traditionally. Looks like when using workflow, this MUST not be used which is a little counter intuitive. Any specific reasons why it is this way?

The argument name for this function is new_data not newdata

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.