【问题标题】:tidymodels roc auc results in multiple classification are affected by first level of factortidymodels roc auc 多分类结果受一级因素影响
【发布时间】:2023-01-07 00:21:25
【问题描述】:

使用 iris 数据集,使用迭代搜索和 roc_auc 调整 knn 分类器作为多重分类的指标。

每个潜在模型的一个 AUC 结果按预期计算,但是,该值不稳定,但受以下因素影响:

  • levels ("setosa", "virginica", "versicolor")在初始数据集的物种列中的顺序
  • roc_auc(truth = Species, .pred_setosa, .pred_virginica,.pred_versicolor) 中列的顺序
  1. 这是否表明 AUC 的计算方法类似于将 Species 列的第一级设置为正事件(这在二元分类中是预期的,而在多重分类中,单个 AUC 基于例如一个对所有比较会合适吗)?

  2. 如果是这样,有没有办法根据例如“one vs all comparisons”产生的所有AUC值的平均AUC值?

  3. 是否也可以在迭代搜索时在metric_set中实现?

    预先感谢您对我们的支持!

    library(tidyverse)
    library(tidymodels)
    tidymodels_prefer()
    
    df <- iris %>% 
      mutate(Species = factor(Species,levels = c("virginica", "versicolor", "setosa")))
    
    splits <- initial_split(df, strata = Species, prop = 4/5)
    df_train <- training(splits)
    df_test  <- testing(splits)
    
    df_rec <- 
      recipe(Species ~ ., data = df_train) 
    
    knn_model <- nearest_neighbor(neighbors = tune()) %>% 
      set_engine("kknn") %>% 
      set_mode("classification")
    
    
    df_wflow <- 
      workflow() %>%
      add_model(knn_model) %>%
      add_recipe(df_rec) 
    
    set.seed(2023)
    knn_cv <-
      df_wflow %>%
      tune_bayes(
        metrics = metric_set(roc_auc),
        resamples = vfold_cv(df_train, strata = "Species", v = 2),
        control = control_bayes(verbose = TRUE, save_pred = TRUE)
      )
    
    cv_train_metrics <- knn_cv %>%  
      collect_predictions() %>%                  
      group_by(.config, id) %>%
      roc_auc(truth = Species, .pred_setosa, .pred_virginica,.pred_versicolor)
    

【问题讨论】:

    标签: r machine-learning tidymodels


    【解决方案1】:

    roc_auc() 期望具有概率估计的列与因子水平的顺序相同。为此,我们将make the documentation better

    默认情况下,我们使用 Hand and Till 的方法来计算单个多类 ROC 曲线下的面积。

    所以这是不是默认情况下做多条 ROC 曲线。您可以更改 estimator 参数以执行不同类型的 averaging methods though 但我不建议将其用于此指标。

    【讨论】:

      猜你喜欢
      • 2020-11-27
      • 2020-10-01
      • 1970-01-01
      • 2019-03-03
      • 2020-02-23
      • 2021-06-12
      • 2017-10-25
      • 2019-11-10
      • 2015-10-17
      相关资源
      最近更新 更多