CARET. 数据分割与trainControl之间的关系

15

我认真阅读了CARET文档:http://caret.r-forge.r-project.org/training.html,浏览了相关文章,现在已经很清楚了(网站上的例子帮了很大忙!),但是我仍然对trainControl函数的两个参数之间的关系感到困惑:

method 
index

并且caret中trainControl与数据分割函数(例如createDataPartitioncreateResamplecreateFoldscreateMultiFolds)之间的相互作用。

为了更好地阐述我的问题,让我使用文档中的以下示例:

data(BloodBrain)
set.seed(1)
tmp <- createDataPartition(logBBB,p = .8, times = 100)
trControl = trainControl(method = "LGOCV", index = tmp)
ctreeFit <- train(bbbDescr, logBBB, "ctree",trControl=trControl)

我的问题是:

  1. 如果我使用 createDataPartition(我假设它执行分层自助法),就像上面的例子一样,并将结果作为 index 传递给 trainControl,我需要在调用 trainControl 中使用 LGOCV 作为方法吗?如果我使用另一个方法(例如 cv),会有什么区别?在我看来,一旦你固定了 index,你实质上选择了交叉验证的类型,所以如果你使用 index,我不确定 method 扮演了什么角色。

  2. createDataPartitioncreateResample之间的区别是什么?是 createDataPartition 执行了分层自助法,而 createResample 没有吗?

3)如何使用caret进行分层k折(例如10折)交叉验证?以下内容是否可行?

tmp <- createFolds(logBBB, k=10, list=TRUE,  times = 100)
trControl = trainControl(method = "cv", index = tmp)
ctreeFit <- train(bbbDescr, logBBB, "ctree",trControl=trControl)
1个回答

1

如果你不确定使用索引时方法的作用,为什么不应用所有方法并比较结果呢?这是一种盲目的比较方法,但它可以给你一些直觉。

  methods <- c('boot', 'boot632', 'cv', 
               'repeatedcv', 'LOOCV', 'LGOCV')

我创建了我的索引:
  n <- 100
  tmp <- createDataPartition(logBBB,p = .8, times = n)

我对我的方法列表应用了 trainControl,并且从结果中删除了索引,因为它对于所有的方法都是通用的。

ll <- lapply(methods,function(x)
         trControl = trainControl(method = x, index = tmp))
ll <- sapply(ll,'[<-','index', NULL)

因此我的ll是:

                 [,1]      [,2]      [,3]      [,4]         [,5]      [,6]     
method            "boot"    "boot632" "cv"      "repeatedcv" "LOOCV"   "LGOCV"  
number            25        25        10        10           25        25       
repeats           25        25        1         1            25        25       
verboseIter       FALSE     FALSE     FALSE     FALSE        FALSE     FALSE    
returnData        TRUE      TRUE      TRUE      TRUE         TRUE      TRUE     
returnResamp      "final"   "final"   "final"   "final"      "final"   "final"  
savePredictions   FALSE     FALSE     FALSE     FALSE        FALSE     FALSE    
p                 0.75      0.75      0.75      0.75         0.75      0.75     
classProbs        FALSE     FALSE     FALSE     FALSE        FALSE     FALSE    
summaryFunction   ?         ?         ?         ?            ?         ?        
selectionFunction "best"    "best"    "best"    "best"       "best"    "best"   
preProcOptions    List,3    List,3    List,3    List,3       List,3    List,3   
custom            NULL      NULL      NULL      NULL         NULL      NULL     
timingSamps       0         0         0         0            0         0        
predictionBounds  Logical,2 Logical,2 Logical,2 Logical,2    Logical,2 Logical,2

有趣。谢谢!我很难将你的答案与我的问题联系起来。基于此,你认为 index 在这里扮演了什么角色呢? - Amelio Vazquez-Reina
@user273158 你是说索引的作用吗?索引只是你的临时向量...你的分区。 - agstudy
嗯,但是像boot(引导)这样的方法如何使用index中指定的分区呢?我理解引导是一种交叉验证的方法(用替换样本进行训练,并在剩下的部分上进行评估),但不知道index在引导中是如何使用的。 - Amelio Vazquez-Reina
1
@user273158 是的,我知道。我不确定...但我认为你的猜测是正确的。一旦你修复了索引,你就在进行一种预采样(离线),而使用方法则是在线采样...我正在验证一些东西,之后会发布我的最终答案... - agstudy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接