Error in UseMethod("filter") : no applicable method for 'filter' applied to an object of class "NULL"

2.6k views Asked by At

I am actually using Tidymodels package on R to study a multi-class classification problem. I have trained several models using Workflow sets, and in my recipe I added a step taken there to replace NA values with a constant. The models that I included in the workflow are:

mlp <-
  mlp(hidden_units = tune(), penalty = tune(), epochs = tune()) %>%
  set_engine('nnet') %>%
  set_mode('classification')

multinom <-
  multinom_reg(penalty = tune(), mixture = tune()) %>%
  set_engine('glmnet')

rand_forest <-
  rand_forest(mtry = tune(), min_n = tune()) %>%
  set_engine('ranger') %>%
  set_mode('classification')

tabnet <- tabnet(mode="classification", batch_size= 126, virtual_batch_size= 128, epochs= 1,
                 num_steps = tune(), learn_rate = tune())%>%
  set_engine("torch", verbose = TRUE)

For some models I tried a recipe with SMOTE ("themis" package), PCA, and normalisation (all in the same workflow by adding the steps to the original recipe). Training and testing went pretty well, so I tried an ensemble of these models (using the package "stacks"):

  tidymodels_prefer()
  
    stack1 <- 
    stacks() %>% 
    add_candidates(res_1)
  
 
  set.seed(2002)
   res1_stack <-
     stack1 %>%
    blend_predictions()

ens <- fit_members(res1_stack)

When I run this last operation (fit_members) I receive this error

Error in UseMethod("filter") : 
  no applicable method for 'filter' applied to an object of class "NULL"

I figured out, reading this and this on GitHub, that it was because the added step "constantimpute" to the recipe. However, I don't exactly know how can I fix it. Someone can help me?

Thank you very much!!!

1

There are 1 answers

0
Chidi On

Before using the filter function, make sure the table you want to filter is loaded. Most times we have the the view() function applied and this prevents the table from being loaded into memory for usage.