Is there anyway we could print iteration when using the caret::train
function in parallel? I know there is option called verbose but it seems it doesn't print anything if I use multicore.
Asked
Active
Viewed 1,859 times
5

Richie Cotton
- 118,240
- 47
- 247
- 360

Tay Shin
- 528
- 4
- 17
-
Are you using RStudio? It directs output in a non-standard way. When I use multicore with it, I don't get any logs but I do with regular R. – topepo Jul 09 '14 at 12:13
-
1Hi Max! I tried with both R studio and R server but non of them prints log if I use registerdomc/makecluster. After some research, I've found that caret package is not the problem but foreach package is the problem. There are some tricks to print out logs. However, most of tricks has to be done inside of foreach loop or the cores have to be registered via makecluster function. But, as you might know, registering cores by makecluster function is just way slower than doMC to run foreach loop(The creator of both packages confirm this). But still, I'm seeking for any other tricks to print of logs – Tay Shin Jul 09 '14 at 13:20
1 Answers
5
I've found a solution. All we need is to register cores via makeCluster function.
library(doSNOW)
cl <- makeCluster(30, outfile="")
registerDoSNOW(cl)
In this way, the log will be printed in console. I've tested on regular R/ Rstudio/ Rserver in mac/window/ubuntu (even AWS)
For example,
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")
will print
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

Tay Shin
- 528
- 4
- 17
-
Same for RStudio, Win7 64-bit, R version 3.3.2, packages: `randomForest_4.6-12`, `doSNOW_1.0.14`, `snow_0.4-2`, `iterators_1.0.8`, `foreach_1.4.3`, `caret_6.0-73`. – m-dz Feb 15 '17 at 10:57
-
Thanks this works, however accuracy is missing. How we print accuracy in the text file? – pauljeba Jun 15 '17 at 06:47