How to add "importance" option in a model exctracted from workflow set in tidymodels approach?

So I selected final model from several untuned models in a workflow_set:

final_train_model <- fit_res %>% 
  extract_workflow(id = "rec_RANDOM_f") %>% 
  finalize_workflow(best_res) %>% 
  fit(train.new)

Then I wanted to look at the variable importance.

final_train_model %>% 
  extract_fit_parsnip() %>% 
  vip()

But, I got warning > "Error in importance.ranger(object) :

No variable importance found. Please use 'importance' option when growing the forest."

How do I add the option to the final selected model?

Sounds like your model was trained using the ranger package engine (I think that's the default engine in rand_forest()). In that case you need to pass the importance argument to that engine, BEFORE you train the model. See more details in ranger::ranger

rand_forest() %>%  set_engine("ranger",  importance = "impurity")

So I need to go back and restate the engine? Can't I use function to update, like update_model? Or recipe? Workflow? Thanks.

This topic was automatically closed 7 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.