【问题标题】:mlr: nested resampling for feature selectionmlr:用于特征选择的嵌套重采样
【发布时间】:2019-08-07 08:03:29
【问题描述】:

我正在运行一个基准实验,在该实验中我调整了一个过滤学习器,类似于 mlr 教程中嵌套重采样下给出的示例,标题为“示例 3:一个任务,两个学习器,带有调整的特征过滤”。我的代码如下:

library(survival)
library(mlr)

data(veteran)
set.seed(24601)
configureMlr(show.learner.output=TRUE, show.info=TRUE)

task_id = "MAS"
mas.task <- makeSurvTask(id = task_id, data = veteran, target = c("time", "status"))
mas.task <- createDummyFeatures(mas.task)

inner = makeResampleDesc("CV", iters=2, stratify=TRUE)  # Tuning
outer = makeResampleDesc("CV", iters=3, stratify=TRUE)  # Benchmarking

cox.lrn <- makeLearner(cl="surv.coxph", id = "coxph", predict.type="response")
cox.filt.uni.thresh.lrn = makeTuneWrapper(
  makeFilterWrapper(
    makeLearner(cl="surv.coxph", id = "cox.filt.uni.thresh", predict.type="response"), 
    fw.method="univariate.model.score", 
    perf.learner=cox.lrn
  ), 
  resampling = inner, 
  par.set = makeParamSet(makeDiscreteParam("fw.threshold", values=c(0.5, 0.6, 0.7))), 
  control = makeTuneControlGrid(),
  show.info = TRUE)

learners = list( cox.filt.uni.thresh.lrn )  
bmr = benchmark(learners=learners, tasks=mas.task, resamplings=outer, measures=list(cindex), show.info = TRUE)

使用此方法似乎外部重采样循环的每次迭代都将使用可能不同的 fw.threshold 值 - 它将使用在内部循环中确定的最佳值。我的问题是,这是否可以接受,或者最好先使用 tuneParams 和交叉验证调整该参数,然后使用之前调整的参数运行基准测试,如下所示:

library(survival)
library(mlr)

data(veteran)
set.seed(24601)
configureMlr(show.learner.output=TRUE, show.info=TRUE)

task_id = "MAS"
mas.task <- makeSurvTask(id = task_id, data = veteran, target = c("time", "status"))
mas.task <- createDummyFeatures(mas.task)

inner = makeResampleDesc("CV", iters=2, stratify=TRUE)  # Tuning
outer = makeResampleDesc("CV", iters=3, stratify=TRUE)  # Benchmarking

cox.lrn <- makeLearner(cl="surv.coxph", id = "coxph", predict.type="response")
cox.filt.uni.thresh.lrn = 
  makeFilterWrapper(
    makeLearner(cl="surv.coxph", id = "cox.filt.uni.thresh", predict.type="response"), 
    fw.method="univariate.model.score", 
    perf.learner=cox.lrn
  )
params = makeParamSet(makeDiscreteParam("fw.threshold", values=c(0.5, 0.6, 0.7)))
ctrl = makeTuneControlGrid()

tuned.params = tuneParams(cox.filt.uni.thresh.lrn, mas.task, resampling = inner, par.set=params, control=ctrl, show.info = TRUE)
tuned.lrn = setHyperPars(cox.filt.uni.thresh.lrn, par.vals = tuned.params$x)

learners = list( tuned.lrn )  
bmr = benchmark(learners=learners, tasks=mas.task, resamplings=outer, measures=list(cindex), show.info = TRUE)

在这种情况下,第二种方法的结果稍差,但我想知道哪种方法是正确的。

【问题讨论】:

    标签: r mlr


    【解决方案1】:

    使用这种方法似乎每次迭代外部重采样 循环将为 fw.threshold 使用可能不同的值 - 它会 使用在内部循环中确定的最佳值。我的问题 是,这是可以接受的还是调整该参数会更好 首先,使用 tuneParams 和交叉验证,然后运行 使用之前调整的参数进行基准测试,如下所示:

    不,因为在这种情况下,您的模型已经看到了数据。 这引入了偏见。 您应该在 CV 中针对每个折叠分别进行所有优化。 所以方法#1是正确的。

    此外,我建议不要使用网格搜索,而是使用随机搜索或 MBO。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-31
      • 2019-01-12
      • 1970-01-01
      相关资源
      最近更新 更多