【问题标题】:Can we use a pre-defined column for CV (resampling) in mlr?我们可以在 mlr 中为 CV(重采样)使用预定义的列吗?
【发布时间】:2019-02-10 03:23:09
【问题描述】:

在mlrR包中进行交叉验证(重采样),通常需要调用makeResampleDesc函数来指定方法和折叠。

我的问题是:

  1. 是否可以将预定义列用作折叠列?或者,
  2. mlr 中的 makeResampleDesc 确保创建的折叠是一致的(在同一原因种子下的不同学习者之间),并且可以导出以进行进一步操作?

【问题讨论】:

    标签: r machine-learning mlr


    【解决方案1】:

    重采样描述独立于任何学习者;您可以将一个与多个学习者一起使用并获得相同的折叠。如果要将重采样结果链接回原始数据,还可以从重采样结果中提取折叠数。

    您可以使用makeClassifTask 的blocking 参数将数据中的列用作折叠列。来自帮助:

    阻塞:[‘因素’]

          An optional factor of the same length as the number of
          observations. Observations with the same blocking level
          “belong together”. Specifically, they are either put all in
          the training or the test set during a resampling iteration.
          Default is ‘NULL’ which means no blocking.
    

    【讨论】:

      【解决方案2】:

      我遇到了类似的问题。

      尝试以下代码我无法获得相同的学习者:

      library(mlr)
      set.seed(123)
      K_Fold = 3
      rdesc <- makeResampleDesc("CV", iters = K_Fold)
      r <- resample("regr.rpart", bh.task, rdesc, show.info = FALSE, extract = getFeatureImportance, measures = medae)
      KFoldIndex <- getResamplingIndices(r)
      r2 <- resample("regr.glm", bh.task, rdesc, show.info = FALSE, measures = medae)
      KFoldIndex2 <- getResamplingIndices(r2)
      

      另一方面,如果您使用 makeResampleInstance,您可以将相同的索引应用于不同的独立学习者。可以在这里找到:https://mlr.mlr-org.com/articles/tutorial/resample.html:

      rdesc = makeResampleDesc("CV", iters = K_Fold)
      rin = makeResampleInstance(rdesc, size = nrow(iris))
      r.lda = resample("classif.lda", iris.task, rin, show.info = FALSE)
      r.rpart = resample("classif.rpart", iris.task, rin, show.info = FALSE)
      
      getResamplingIndices(r.lda)
      getResamplingIndices(r.rpart)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多