TidyModels: Fold2: preprocessor 1/1, model 1/1 (predictions): Error: Missing data in columns

Viewed 21

I am creating a random forest regression model using TidyModels. Currently I am fitting my resamples with the following chunks of code.

Creating Cross-Validated Folds

lead_time_folds <- vfold_cv(   training_data
                              , v = 5
                              , strata = LEAD_TIME_ACTUAL_BUSINESS_DAYS)

Fitting Resamples with Workflow:

lead_time_rf_fit <- lead_time_workflow %>% 
  fit_resamples(resamples = lead_time_folds)

The Error when Excecuting Code Above

Fold2: preprocessor 1/1, model 1/1 (predictions): Error: Missing data in columns: CONFIGURATION.
Fold5: preprocessor 1/1, model 1/1 (predictions): Error: Missing data in columns: STR_RGN_NBR.

*What Confuses me is I have taken steps to remove NAs from my dataset by doing the following

train_data_test <-  train_data_test %>%
  na.omit(train_data_test) 

To Ensure I have no NAs in my data I evaluated the results by doing the following:

train_data_test %>%  
  profile_missing() %>%  
  View()

Which yields & confirms no NAs enter image description here

And

lead_time_recipe %>% prep() 

Which yields

Recipe

    Inputs:
    
          role #variables
       outcome          1
     predictor         10
    
    Training data contained 133842 data points and no missing data.
    
    Operations:
    
    Correlation filter removed no terms [trained]

I will mention that my datapoint that I am pulling from has datapoints that are double 0 or '00' but I figured that wouldn't be an issue if its a factor?

1 Answers

According to the code you are showing, you are only removing observations with missing values from the test data set. You also need to make sure that the training data set is free from missing values.

You can do this by running

training_data <- na.omit(training_data) 

Before you pass training_data to vfold_cv(), or by dealing with the missing values in the preprocessing such as by applying imputation using {recies}.

Related