r package caret - 使用parallel时的print迭代

时间:2014-07-07 12:25:35

标签: r r-caret

我们是否可以在并行使用caret::train函数时打印迭代?我知道有一个名为verbose的选项,但是如果我使用多核,它似乎没有打印任何东西。

1 个答案:

答案 0 :(得分:5)

我找到了解决方案。 我们所需要的只是通过makeCluster函数注册核心。

library(doSNOW)
cl <- makeCluster(30, outfile="")
registerDoSNOW(cl)

这样,日志将在控制台中打印。 我在mac / window / ubuntu(甚至是AWS)的常规R / Rstudio / Rserver上进行了测试

例如,

iris <- iris[1:100,]
iris$Species <- as.factor(as.character(iris$Species))

tc <- trainControl(method="LGOCV",
                   summaryFunction=twoClassSummary,
                   classProb=T,verboseIter=TRUE)
train.rf <- train(Species ~ .,data=iris, 
                  method="rf", trControl=tc, 
                   metric =  "ROC")

将打印

Type: EXEC 
loaded caret and set parent environment
Type: EXEC 
loaded caret and set parent environment
Type: EXEC 
Type: EXEC 
+ Resample01: mtry=2 
+ Resample01: mtry=3 
- Resample01: mtry=3 
Type: EXEC 
+ Resample02: mtry=2 
- Resample01: mtry=2 
Type: EXEC 
+ Resample01: mtry=4 
- Resample02: mtry=2 
Type: EXEC 
+ Resample02: mtry=3 
- Resample01: mtry=4 
Type: EXEC 
+ Resample02: mtry=4 
- Resample02: mtry=3 
Type: EXEC 
+ Resample03: mtry=2 
- Resample02: mtry=4 
Type: EXEC 
+ Resample03: mtry=3 
- Resample03: mtry=2 
Type: EXEC 
+ Resample03: mtry=4 
- Resample03: mtry=3 
Type: EXEC 
+ Resample04: mtry=2 
- Resample03: mtry=4 
Type: EXEC 
+ Resample04: mtry=3 
- Resample04: mtry=2 
Type: EXEC 
+ Resample04: mtry=4 
- Resample04: mtry=3 
Type: EXEC 
+ Resample05: mtry=2 
- Resample04: mtry=4 
Type: EXEC 
+ Resample05: mtry=3 
- Resample05: mtry=2 
Type: EXEC 
+ Resample05: mtry=4 
- Resample05: mtry=3 
Type: EXEC 
+ Resample06: mtry=2 
- Resample05: mtry=4 
Type: EXEC 
+ Resample06: mtry=3 
- Resample06: mtry=2 
Type: EXEC 
+ Resample06: mtry=4 
- Resample06: mtry=3 
Type: EXEC 
+ Resample07: mtry=2 
- Resample06: mtry=4 
Type: EXEC 
- Resample07: mtry=2 
+ Resample07: mtry=3 
Type: EXEC 
+ Resample07: mtry=4 
- Resample07: mtry=3 
- Resample07: mtry=4 
Type: EXEC 
Type: EXEC 
+ Resample08: mtry=2 
+ Resample08: mtry=3 
- Resample08: mtry=3 
Type: EXEC 
+ Resample09: mtry=2 
- Resample08: mtry=2 
Type: EXEC 
+ Resample08: mtry=4 
- Resample09: mtry=2 
Type: EXEC 
+ Resample09: mtry=3 
- Resample08: mtry=4 
Type: EXEC 
+ Resample09: mtry=4 
- Resample09: mtry=3 
Type: EXEC 
+ Resample10: mtry=2 
- Resample09: mtry=4 
Type: EXEC 
+ Resample10: mtry=3 
- Resample10: mtry=2 
Type: EXEC 
+ Resample10: mtry=4 
- Resample10: mtry=3 
Type: EXEC 
+ Resample11: mtry=2 
- Resample10: mtry=4 
Type: EXEC 
+ Resample11: mtry=3 
- Resample11: mtry=2 
Type: EXEC 
+ Resample11: mtry=4 
- Resample11: mtry=3 
Type: EXEC 
+ Resample12: mtry=2 
- Resample11: mtry=4 
Type: EXEC 
+ Resample12: mtry=3 
- Resample12: mtry=2 
Type: EXEC 
+ Resample12: mtry=4 
- Resample12: mtry=3 
Type: EXEC 
+ Resample13: mtry=2 
- Resample12: mtry=4 
Type: EXEC 
+ Resample13: mtry=3 
- Resample13: mtry=2 
Type: EXEC 
+ Resample13: mtry=4 
- Resample13: mtry=3 
Type: EXEC 
+ Resample14: mtry=2 
- Resample14: mtry=2 
Type: EXEC 
+ Resample14: mtry=4 
- Resample14: mtry=4 
Type: EXEC 
+ Resample15: mtry=2 
- Resample15: mtry=2 
Type: EXEC 
+ Resample15: mtry=3 
- Resample15: mtry=3 
Type: EXEC 
+ Resample15: mtry=4 
- Resample13: mtry=4 
Type: EXEC 
+ Resample14: mtry=3 
- Resample15: mtry=4 
Type: EXEC 
+ Resample16: mtry=2 
- Resample14: mtry=3 
Type: EXEC 
+ Resample16: mtry=3 
- Resample16: mtry=2 
Type: EXEC 
+ Resample16: mtry=4 
- Resample16: mtry=3 
Type: EXEC 
+ Resample17: mtry=2 
- Resample17: mtry=2 
Type: EXEC 
+ Resample17: mtry=4 
- Resample17: mtry=4 
Type: EXEC 
+ Resample18: mtry=2 
- Resample18: mtry=2 
Type: EXEC 
+ Resample18: mtry=3 
- Resample16: mtry=4 
Type: EXEC 
+ Resample17: mtry=3 
- Resample18: mtry=3 
Type: EXEC 
+ Resample18: mtry=4 
- Resample17: mtry=3 
Type: EXEC 
+ Resample19: mtry=2 
- Resample18: mtry=4 
Type: EXEC 
+ Resample19: mtry=3 
- Resample19: mtry=2 
Type: EXEC 
+ Resample19: mtry=4 
- Resample19: mtry=3 
Type: EXEC 
+ Resample20: mtry=2 
- Resample19: mtry=4 
Type: EXEC 
+ Resample20: mtry=3 
- Resample20: mtry=2 
Type: EXEC 
+ Resample20: mtry=4 
- Resample20: mtry=3 
Type: EXEC 
+ Resample21: mtry=2 
- Resample20: mtry=4 
Type: EXEC 
+ Resample21: mtry=3 
- Resample21: mtry=2 
Type: EXEC 
+ Resample21: mtry=4 
- Resample21: mtry=3 
Type: EXEC 
- Resample21: mtry=4 
+ Resample22: mtry=2 
Type: EXEC 
+ Resample22: mtry=3 
- Resample22: mtry=3 
Type: EXEC 
+ Resample23: mtry=2 
- Resample22: mtry=2 
Type: EXEC 
+ Resample22: mtry=4 
- Resample23: mtry=2 
Type: EXEC 
+ Resample23: mtry=3 
- Resample22: mtry=4 
Type: EXEC 
+ Resample23: mtry=4 
- Resample23: mtry=3 
Type: EXEC 
+ Resample24: mtry=2 
- Resample23: mtry=4 
Type: EXEC 
+ Resample24: mtry=3 
- Resample24: mtry=2 
Type: EXEC 
+ Resample24: mtry=4 
- Resample24: mtry=3 
Type: EXEC 
+ Resample25: mtry=2 
- Resample24: mtry=4 
Type: EXEC 
+ Resample25: mtry=3 
- Resample25: mtry=2 
Type: EXEC 
+ Resample25: mtry=4 
- Resample25: mtry=3 
- Resample25: mtry=4 
Aggregating results
Selecting tuning parameters
Fitting mtry = 2 on full training set