2014-07-07 36 views
4

有沒有辦法在平行使用caret::train函數時打印迭代?我知道有一個稱爲verbose的選項,但是如果我使用多核,它似乎不會打印任何內容。r包裝符號 - 使用並行打印迭代

+0

是否使用RStudio?它以非標準方式指導輸出。當我使用多核時,我沒有得到任何日誌,但是我使用普通的R。 – topepo

+1

Hi Max!我試着用R studio和R server,但是如果我使用registerdomc/makecluster,它們都不會打印日誌。經過一番研究,我發現脫字符包不是問題,但是包裝是問題。有一些技巧可以打印日誌。但是,大多數技巧必須在foreach循環內完成,或者核心必須通過makecluster函數註冊。但是,正如你可能知道的那樣,通過makecluster函數註冊核心只是比運行foreach循環的doMC慢得多(兩個軟件包的創建者都證實了這一點)。但是,我仍然在尋找打印日誌的其他技巧 –

回答

4

我找到了解決方案。 我們需要的是通過makeCluster函數註冊核心。

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

通過這種方式,日誌將被打印在控制檯中。 我在Mac /窗/ 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 
+0

與RStudio,Win7 64位,R版本3.3.2相同,包:'randomForest_4.6-12','doSNOW_1.0.14','snow_0。 4-2','iterators_1.0.8','foreach_1.4.3','caret_6.0-73'。 –

+0

謝謝你的工作,但是正確性不見了。我們如何在文本文件中打印準確性? – pauljeba