插入符中的并行训练执行失败,未找到功能 [英] Parallel execution of train in caret fails with function not found

查看:163
本文介绍了插入符中的并行训练执行失败,未找到功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我更新了R程序包,从那以后,train函数的并行执行失败.

yesterday I updated my R packages and since then parallel execution of the train function fails.

似乎从工作程序内部调用的某些功能不可用.这些功能至少是flatTable和probFunction.

It seems like some functions that are called from within the workers are not available. These functions are at least flatTable and probFunction.

我在生产机器上遇到此问题,并能够在干净的Windows 7 x64 VM上重现它.

I experiencing this issues on my production machine, and was able to reproduce it on a clean Windows 7 x64 VM.

我在下面添加了一个最小的工作示例.尊敬的stackoverflow用户:非常感谢您的帮助!

I added a minimal working example below. Dear users of stackoverflow: Any help is appreciated!

# R 3.0.2 x64, RStudio Version 0.98.490, Windows 7 x64

data(iris)
library(caret) # 6.0-21
library(doParallel) # 1.0.6

model <- "rf"

# Fail
?probFunction
?flatTable

fitControl <- trainControl(
  method = "repeatedcv"
  , number = 5  ## 5-fold CV
  , repeats = 1   ## repeated one times
  , verboseIter =TRUE
)

#### Sequential Version ####

# Runs
train(Species ~ ., data = iris, method = model, trControl = fitControl)

#### Parallelized version ####

# Fails with 
# Error in e$fun(obj, substitute(ex), parent.frame(), e$data) : 
#  worker initialization failed: Error in eval(expr, envir, enclos): could not find function "flatTable"
cl <- makeCluster(3)
registerDoParallel(cl)

train(Species ~ ., data = iris, method = model, trControl = fitControl)

stopCluster(cl)

# Fails with 
# Error in { : task 1 failed - "could not find function "probFunction""
fitControl <- trainControl(
  method = "repeatedcv"
  , number = 5  ## 5-fold CV
  , repeats = 1   ## repeated one times
  , verboseIter =TRUE
  , classProbs = TRUE
)

cl <- makeCluster(3)
registerDoParallel(cl)

train(Species ~ ., data = iris, method = model, trControl = fitControl)

stopCluster(cl)

#### Again sequential version ####

# Fails with
# Error in summary.connection(connection) : invalid connection
train(Species ~ ., data = iris, method = model, trControl = fitControl)

R会话信息

R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252   

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods   base    

other attached packages:
[1] e1071_1.6-1        class_7.3-9        randomForest_4.6-7 doParallel_1.0.6   iterators_1.0.6  
[6] foreach_1.4.1      caret_6.0-21       ggplot2_0.9.3.1    lattice_0.20-23  

loaded via a namespace (and not attached):
[1] car_2.0-19         codetools_0.2-8    colorspace_1.2-4   compiler_3.0.2     dichromat_2.0-0  
 [6] digest_0.6.4       grid_3.0.2         gtable_0.1.2       labeling_0.2       MASS_7.3-29      
[11] munsell_0.4.2      nnet_7.3-7         plyr_1.8           proto_0.3-10       RColorBrewer_1.0-5
[16] reshape2_1.2.2     scales_0.2.3       stringr_0.6.2      tools_3.0.2      

推荐答案

使用doParallel,doSNOW和doMPI时,插入符号6.0-21中的错误引起了您收到的错误.它已在R-forge的6.0-22版中修复,但尚未发布到CRAN.如果您不想等待新版本发布,则可以:

The error that you're getting is caused by a bug in caret 6.0-21 when using doParallel, doSNOW, and doMPI. It's been fixed in version 6.0-22 in R-forge, but hasn't been released to CRAN yet. If you don't want to wait for the new version to be released, you can:

  1. 降级为插入符号5.x
  2. 从R-forge安装插入符号6.0-22
  3. 从R-forge而非doParallel安装并使用doSNOW 1.0.10

此问题是由CRAN策略更改导致的,该更改禁止使用:::运算符,即使在同一包中引用未导出的函数也是如此.

The problem was caused by a change in CRAN policy that forbids the use of the ::: operator, even when referencing non-exported functions from within the same package.

更新

Caret 6.0-22于2014年1月18日发布到CRAN.这应该可以使用带有doSNOW和类似并行后端的插入符号解决报告的问题.

Caret 6.0-22 was released to CRAN on 2014-01-18. This should resolve the reported problem using caret with doSNOW and similar parallel backends.

这篇关于插入符中的并行训练执行失败,未找到功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆