【问题标题】:Calculating AUC Leave-One-Out cross validation in mlR?在 mlR 中计算 AUC Leave-One-Out 交叉验证?
【发布时间】:2016-01-19 16:00:58
【问题描述】:

这是一个简单的问题,只是为了确保我不会以愚蠢的方式这样做。我想使用auc 作为我在 mlr 中的度量,并且由于样本量小,我也在使用 LOO。当然,在LOO交叉验证方案中,测试样本总是只有一个实例,所以auc是无法计算出来的。当然,我们可以在之后计算它,查看预测,当我们想将它用作嵌套交叉验证的内部循环中的度量时,就会出现问题。像这样的东西(你必须定义你自己的binaryTask):

require(mlr)    
#for example purposes we will decide which one is better, vanilla LDA or
#vanilla SVM, in the task specified below
bls = list(makeLearner("classif.lda"),makeLearner("classif.svm"))
#modelMultiplexer allows us to search whole parameter spaces between models
#as if the models themselves were parameters
lrn = makeModelMultiplexer(bls)
#to calculate AUC we need some continuous output, so we set 
#predictType to probabilities
lrn = setPredictType(lrn, "prob")
lrn = setId(lrn, "Model Multiplexer")
#here we could pass the parameters to be tested to both SVM and LDA,
#let's not pass anything so we test the vanilla classifiers instead
ps = makeModelMultiplexerParamSet(lrn)
#finally, the resample strategy, Leave-One-Out ("LOO") in our case
rdesc = makeResampleDesc("LOO")
#parameter space search strategy, in our case we only have one parameter:
#the model. So, a simple grid search will do the trick
ctrl = makeTuneControlGrid()
#The inner CV loop where we choose the best model in the validation data
tune = makeTuneWrapper(lrn, rdesc, par.set = ps, control = ctrl, measure = auc, show.info = FALSE) 
#The outer CV loop where we obtain the performace of the selected model 
#in the test data. mlR is a great interface, we could have passed a list 
#of classifiers and tasks here instead and do it all in one go 
#(beware your memory limitation!)
res = benchmark(tune, binaryTask, rdesc, measure = auc)

你根本不能像这样在两个循环中使用auc。我们如何让mlr 评估所有测试样本的度量,而不是每次都进行唯一的重新采样?

【问题讨论】:

    标签: r classification cross-validation auc mlr


    【解决方案1】:

    您可以对内部循环使用不同的重采样策略,然后使用auc

    library(mlr)    
    
    ps = makeParamSet(
      makeNumericLearnerParam(id = "cp", default = 0.01, lower = 0, upper = 1)
    )
    ctrl = makeTuneControlRandom(maxit = 10)
    inner = makeResampleDesc("Subsample")
    lrn = makeLearner("classif.rpart", predict.type = "prob")
    tune = makeTuneWrapper(lrn, resampling = inner, par.set = ps, control = ctrl, measure = auc)
    
    outer = makeResampleDesc("LOO")
    r = resample(tune, bc.task, resampling = outer, extract = getTuneResult, measure = auc)
    

    您也可以只获取重采样结果并在其上计算任意性能度量,例如performance(r$pred, auc).

    【讨论】:

    • 所有其他重采样策略都可以让我计算auc,当然,但我想根据我的数据集使用LOO。但如果没有其他答案,我愿意跳到 Monte-Carlo CV。谢谢!
    • 好的,那我不确定你在问什么。您不能将auc 与 LOOCV 一起使用,因此您必须使用其他东西 :)
    • 我想在整个测试样本上计算auc,即LOOCV的每次迭代,而不是单独在每个样本中,这显然是不可能的。这对我来说似乎可行,但我不确定mlR 是否允许这样做。
    • 这没有意义——你每次都会得到相同的数字。这与为外部 CV 执行此操作相同。
    • 你只会得到一个数字,就像你在做LOO时只得到一个准确度acc估计一样。真的看不出区别。
    猜你喜欢
    • 2021-06-18
    • 2023-03-05
    • 2021-04-03
    • 2019-11-19
    • 2020-04-09
    • 1970-01-01
    • 2019-11-21
    • 1970-01-01
    • 2021-11-13
    相关资源
    最近更新 更多