简体   繁体   English

tidymodels metric_set:错误:`metric_set()` 的所有输入都必须是函数。 这些输入不是:(2)

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

I have used recipe() function in tidymodels packages for imputation missing values and fixing imbalanced data.我在tidymodels包中使用了recipe()函数来填补缺失值和修复不平衡的数据。

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.它一直工作到这里现在我使用metric_set()函数来适应每个重采样。

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!非常感谢您的帮助!

May be there is another variable named accuracy that is defined in your environment.可能在您的环境中定义了另一个名为accuracy变量。 Try typing yardstick::accuracy instead.尝试输入yardstick::accuracy

mer_metrics <- metric_set(roc_auc, yardstick::accuracy, sensitivity, specificity) mer_metrics <- metric_set(roc_auc, yardstick::accuracy, 灵敏度, 特异性)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “ROC”度量标准不在结果集中 - “ROC” metric not in result set 在带有 tidymodels 的 r 中:警告消息:“所有模型在 [fit_resamples()] 中均失败。请参阅 `.notes` 列。” 内部:错误:在指标中:`roc_auc` - In r with tidymodels: Warning message: "All models failed in [fit_resamples()]. See the `.notes` column." internal: Error: In metric: `roc_auc` R将功能列表应用于同一组输入 - R apply list of functions to the same set of inputs tidyverse 错误错误:所有 select() 输入必须解析为整数列位置 - tidyverse error Error: All select() inputs must resolve to integer column positions 结果集中没有显示如何解决“精度”指标。 将使用AUC代替” - How to fix “The metric ”Accuracy“ was not in the result set. AUC will be used instead” R-Caret,caretList,度量“Accuracy”不在结果集中 - R-Caret, caretList, The metric “Accuracy” was not in the result set 为什么 R 中的 function 没有在所有输入集上运行? 我收到此错误:替换有 1 行,数据有 5 - Why is the function in R not running across all set of inputs? I am getting this error: replacement has 1 row, data has 5 R caret错误:出问题了; 所有精度指标值均缺失: - R caret Error: Something is wrong; all the Accuracy metric values are missing: 脱字号-错误-出了点问题-缺少所有ROC指标值: - caret - error - Something is wrong - all the ROC metric values are missing: 将Shiny中动态输入的默认值设置为不同 - Set default values of dynamic inputs in Shiny to be different
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM