【问题标题】:r package caret-Print iteration when using parallelr package caret-Print 使用并行时的迭代
【发布时间】:2014-08-27 22:27:12
【问题描述】:

在并行使用caret::train 函数时,我们是否可以打印迭代?我知道有一个称为详细的选项,但如果我使用多核,它似乎不会打印任何内容。

【问题讨论】:

  • 你在使用 RStudio 吗?它以非标准方式引导输出。当我使用多核时,我没有得到任何日志,但我使用常规 R。
  • 嗨,麦克斯!我尝试使用 R studio 和 R 服务器,但如果我使用 registerdomc/makecluster,它们都不会打印日志。经过一番研究,我发现 caret 包不是问题,而是 foreach 包是问题。有一些技巧可以打印出日志。但是,大多数技巧必须在 foreach 循环内完成,或者必须通过 makecluster 函数注册内核。但是,您可能知道,通过 makecluster 函数注册内核比 doMC 运行 foreach 循环要慢得多(这两个包的创建者都证实了这一点)。但是,我仍在寻找其他打印日志的技巧

标签: r r-caret


【解决方案1】:

我找到了解决方案。 我们只需要通过 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

【讨论】:

  • RStudio 相同,Win7 64 位,R 版本 3.3.2,包:randomForest_4.6-12doSNOW_1.0.14snow_0.4-2iterators_1.0.8foreach_1.4.3caret_6.0-73
  • 感谢这项工作,但准确性缺失。我们如何在文本文件中打印准确性?
猜你喜欢
  • 1970-01-01
  • 2015-06-03
  • 1970-01-01
  • 1970-01-01
  • 2016-07-04
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 2017-01-24
相关资源
最近更新 更多