Tidypredict does not incorporate Recipes

127 Views Asked by At

I fit a model with logistic regression by tidymodels. The function tidypredict_fit extract the formula but I note that it does not incorporate the preprocess in the recipes. How can I extract the model formula with the necessary preprocess?

    set.seed(123)
    split <- initial_split(lepto, prop = 0.75, strata = 'composite_outcome')
    lepto_train <- training(split)
    letp_test <- testing(split)

rec2 <- recipe(composite_outcome ~ letargy + creatinine + cholestatic_syndrome + pallor + pulmonary_involvement +
                reduced_diuresis + heart_rate + ast + hypotension + leucocytes, data = lepto_train) %>% 
  step_medianimpute(all_numeric()) %>% 
  step_BoxCox(all_numeric()) %>% 
  step_normalize(all_numeric()) %>% 
  step_corr(all_numeric(), threshold = 0.9) %>% 
  step_unknown(all_nominal(), -all_outcomes(), new_level = 'without_information') %>% 
  step_dummy(all_nominal(), -all_outcomes()) %>% 
  step_lincomb(all_predictors()) %>% 
  step_nzv(all_predictors())

## --- Model glm --------------------------------------- ##

model_glm <- logistic_reg(mode = 'classification') %>% 
             set_engine('glm')

## -- workflow ---------------------------------------- ##

work_glm <- workflow() %>% 
  add_recipe(rec2) %>% 
  add_model(model_glm)

## -------Fit --------------------------------------- ##

test_glm <- work_glm %>% 
  last_fit(split)

test_glm %>% collect_metrics()

final_glm <- work_glm %>% 
  fit(lepto_train)


final_glm %>% 
  pull_workflow_fit() %>% 
  tidypredict_fit()


model_logistic <- final_glm %>% 
  pull_workflow_fit()


0

There are 0 best solutions below