R中的doRedis/foreach GBM并行处理错误 [英] doRedis/foreach GBM parallel processing error in R

查看:43
本文介绍了R中的doRedis/foreach GBM并行处理错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用插入符号包运行gbm模型,并尝试通过对doredis包进行并行处理来使其工作.我可以让后端工作人员全部正常运行,但是当他们重新组合到最终模型中时遇到了问题.我收到此错误:

I am running a gbm model using the caret package and trying to get it working using parallel processing with the doredis package. I can get the backend workers all up and running, but am having issues when they recombine into the final model. I am getting this error:

    Error in foreach(j = 1:12, .combine = sum, .multicombine = TRUE) %dopar%  : 
      target of assignment expands to non-language object

这是我第一次尝试运行foreach循环(更不用说像gbm这样的复杂问题了),并且遇到了尝试理解和实现此问题的问题.我已经进行了许多Google搜索,但是在使用gbm实施foreach方面一无所获.这是我的代码:

This is my first time trying to run the foreach loop (let alone on a complex problem like gbm) and am having issues trying to understand and get this implemented. I have done many Google searches and found nothing on implementing foreach with gbm, Any help on understanding foreach would be greatly appreciated. Here is my code:

    set.seed(825)
    library(caret)
    require(foreign)

    data <- read.spss("C:\\Users\\cc\\Documents\\mydata.sav",use.value.labels=TRUE, to.data.frame = TRUE)
    getOption("max.print")
    options(max.print = 99999999)
    set.seed(825)
    start.time <- Sys.time()
    x <- data[, -162]
    y <- data[, 162]
    fitControl = trainControl(method = "cv", number = 8,  allowParallel=TRUE)
     gbmGrid <-  expand.grid(interaction.depth = c(49), n.trees = (1:2), shrinkage = c(0.03), n.minobsinnode = 50)


    require(doRedis)
    registerDoRedis('jobs')
    options('redis:num'=TRUE)
    foreach(j=1:12,.combine=sum,.multicombine=TRUE) %dopar%

    gbmFit <- train(x=x,y=y,"gbm", tuneGrid = gbmGrid, trControl=fitControl)
    gbmFit
    summary(gbmFit)

    end.time <- Sys.time()
    time.taken <- end.time - start.time
    time.taken

UPDATE 根据关于使用某种数据集进行复制的建议,我使用Iris数据集 data<-iris 切换了mydata,并将X和Y更改为 x<-data [,-5] y<-data [,5] ,并且发生了相同的错误.

UPDATE As per a suggestion regarding reproducing with some sort of dataset, I switched mydata with the Iris dataset data <- iris and changed the X and Y to x <- data[, -5] y <- data[, 5] and the same error occurred.

推荐答案

我找到了答案!我联系了redis的创建者,而后者又联系了插入符号的创建者.似乎插入符号会自动处理拆分作业,因此不需要foreach循环.只需完全删除该行,即可正常运行.

I found an answer to this! I got in touch with the creater of redis, which in turn he got in touch with the creator of caret. It seems caret automatically handles splitting jobs up so the foreach loop is not necessary. Just completely remove that line and it will work perfectly.

在一个旁注中,他指示我告诉其他人去gitihub下载最新的doRedis软件包,因为它比当前的doredis软件包更好,但还不准备退出CRAN.

On a side note, he directed me to tell others to go to the gitihub to download the newest doRedis package as it is better than the current doredis package, but not quit ready for CRAN.

使用此代码安装新的doRedis软件包(请注意,您还必须具有 Rtools在运行代码之前安装)

Use this code to install the new doRedis package (note make sure you also have Rtools installed before you run the code)

install.packages("devtools")
devtools::install_github("bwlewis/doRedis")

这篇关于R中的doRedis/foreach GBM并行处理错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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