tidymodels metric_set:Error: All inputs to `metric_set()` must be functions. These inputs are not: (2)

1.2k views Asked by At

I have used recipe()function in tidymodels packages for imputation missing values and fixing imbalanced data.

here is my data;

mer_df <- mer2 %>%
  filter(!is.na(laststagestatus2)) %>% 
  select(Id, Age_Range__c, Gender__c, numberoflead, leadduration, firsttouch, lasttouch, laststagestatus2)%>%
  mutate_if(is.character, factor) %>%
  mutate_if(is.logical, as.integer)


# A tibble: 197,836 x 8
   Id    Age_Range__c Gender__c numberoflead leadduration firsttouch lasttouch
   <fct> <fct>        <fct>            <int>        <dbl> <fct>      <fct>    
 1 0010~ NA           NA                   2     5.99     Dealer IB~ Walk in  
 2 0010~ NA           NA                   1     0        Online Se~ Online S~
 3 0010~ NA           NA                   1     0        Walk in    Walk in  
 4 0010~ NA           NA                   1     0        Online Se~ Online S~
 5 0010~ NA           NA                   2     0.0128   Dealer IB~ Dealer I~
 6 0010~ NA           NA                   1     0        OB Call    OB Call  
 7 0010~ NA           NA                   1     0        Dealer IB~ Dealer I~
 8 0010~ NA           NA                   4    73.9      Dealer IB~ Walk in  
 9 0010~ NA           Male                24     0.000208 OB Call    OB Call  
10 0010~ NA           NA                  18     0.000150 OB Call    OB Call  
# ... with 197,826 more rows, and 1 more variable: laststagestatus2 <fct>

here is my codes;

mer_rec <- recipe(laststagestatus2 ~ ., data = mer_train)%>%
  step_medianimpute(numberoflead,leadduration)%>%
  step_knnimpute(Gender__c,Age_Range__c,fisrsttouch,lasttouch) %>% 
  step_other(Id,firsttouch) %>% 
  step_other(Id,lasttouch) %>% 
  step_dummy(all_nominal(), -laststagestatus2) %>% 
  step_smote(laststagestatus2)
mer_rec %>% prep() %>% juice()


glm_spec <- logistic_reg() %>%
  set_engine("glm")

rf_spec <- rand_forest(trees = 1000) %>%
  set_mode("classification") %>%
  set_engine("ranger")

mer_wf <- workflow() %>%
  add_recipe(mer_rec)

It just works fine until here Now I m using metric_set() function to fit each of resamples.

here is my codes as follows:

 mer_metrics <- metric_set(roc_auc, accuracy, sensitivity, specificity)

glm_rs <- mer_wf %>%
  add_model(glm_spec) %>%
  fit_resamples(
    resamples = mer_folds,
    metrics = mer_metrics,
    control = control_resamples(save_pred = TRUE)

I m getting the error says:

Error: All inputs to `metric_set()` must be functions. These inputs are not: (2).

but it works without accuracy parameter

merco_metrics <- metric_set(roc_auc, sensitivity, specificity)

Anyone have any suggestions on how to do this? Thanks a lot for help!

1

There are 1 answers

0
hnagaty On BEST ANSWER

May be there is another variable named accuracy that is defined in your environment. Try typing yardstick::accuracy instead.

mer_metrics <- metric_set(roc_auc, yardstick::accuracy, sensitivity, specificity)