4 parallel-processing r machine-learning data-mining r-caret
主要问题:
在阅读文档和谷歌搜索之后,我仍然难以确定预先定义重采样指数的情况,例如:
resamples <- createResample(classVector_training, times = 500, list=TRUE)
Run Code Online (Sandbox Code Playgroud)
或预定义的种子,如:
seeds <- vector(mode = "list", length = 501) #length is = (n_repeats*nresampling)+1
for(i in 1:501) seeds[[i]]<- sample.int(n=1000, 1)
Run Code Online (Sandbox Code Playgroud)
我的计划是通过doParallel软件包使用并行处理来训练一堆不同的可重现模型.由于已经设置了种子,是否不需要预定义重新采样?我是否需要以上述方式预定义种子,而不是在trainControl对象中设置seeds = NULL,因为我打算使用并行处理?是否有任何理由预先定义索引和种子,因为我通过搜索谷歌至少看过一次?什么是使用indexOut的原因?
问题:
到目前为止,我已经设法为RF运行良好的列车:
rfControl <- trainControl(method="oob", number = 500, p = 0.7, returnData=TRUE, returnResamp = "all", savePredictions=TRUE, classProbs = TRUE, summaryFunction = twoClassSummary, allowParallel=TRUE)
mtryGrid <- expand.grid(mtry = 9480^0.5) #set mtry parameter to the square root of the number of variables
rfTrain <- train(x = training, y = classVector_training, method = "rf", trControl = rfControl, tuneGrid = mtryGrid)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用method ="baruta"运行train()时:
borutaControl <- trainControl(method="bootstrap", number = 500, p = 0.7, returnData=TRUE, returnResamp = "all", savePredictions=TRUE, classProbs = TRUE, summaryFunction = twoClassSummary, allowParallel=TRUE)
borutaTrain <- train(x = training, y = classVector_training, method = "Boruta", trControl = borutaControl, tuneGrid = mtryGrid)
Run Code Online (Sandbox Code Playgroud)
我最终收到以下错误:
Error in names(trControl$indexOut) <- prettySeq(trControl$indexOut) : 'names' attribute [1] must be the same length as the vector [0]
Run Code Online (Sandbox Code Playgroud)
谁知道为什么?
这里使用了几个不同的随机数,因此我将尝试具体说明哪些种子.
由于已经设置了种子,是否不需要预定义重新采样?
如果你不提供自己的重采样指数的第一件事情是train
,rfe
,sbf
,gafs
,和safs
要做的是创建它们.因此,在调用这些种子之前设置整体种子会控制创建重新采样的随机性.因此,您可以重复调用这些函数,并使用预先设置主种子的相同样本:
set.seed(2346)
mod1 <- train(y ~ x, data = dat, method = "a", ...)
set.seed(2346)
mod2 <- train(y ~ x, data = dat, method = "b", ...)
set.seed(2346)
mod3 <- rfe(x, y, ...)
Run Code Online (Sandbox Code Playgroud)
您可以使用createResamples
或者createFolds
,如果你喜欢,并给那些trainControl
的index
说法了.
关于此的另一个注意事项:如果indexOut
缺失,则保留定义为不用于训练模型的样本.有些情况下这是不好的(见下面的例外),这就是indexOut
存在的原因.
我是否需要以上述方式预定义种子,而不是在trainControl对象中设置seeds = NULL,因为我打算使用并行处理?
这是主要意图.当工作进程启动时,在添加seeds
参数之前无法控制模型拟合内的随机性.你不用必须使用它,但它会导致重复性的模型.
请注意,与重新采样一样,train
如果您不提供种子,则会为您创建种子.它们control$seeds
位于train
对象的元素中.
请注意,trainControl(seeds)
这与创建重新采样无关.
是否有任何理由预先定义索引和种子,因为我通过搜索谷歌至少看过一次?
如果要预先定义重新采样并控制构建模型的工作进程中的任何潜在随机性,则为是.
什么是使用indexOut的原因?
总有专门的情况.它存在的原因是时间序列数据,您可能有数据拆分,不涉及传递给所有样本train
(这是上面提到的例外).看到白色的空间这个图形.
TL/DR
trainControl(seeds)
仅控制模型拟合的随机性train
是控制数据分割的随机性的一种方法马克斯
归档时间: |
|
查看次数: |
2298 次 |
最近记录: |