如何在foreach中使用XGboost并在R中使用doParallel?

时间:2018-03-30 19:01:49

标签: r xgboost parallel-foreach

尝试使用doParallel在foreach中运行xgboost时遇到问题,我使用的是带有32个内核和64个线程的AMD那不勒斯。运行会遇到这部分代码,我希望按顺序将列的最后一行结果放在列表中。

 pg = list()

 c1  = makeCluster(20)
 registerDoParallel(c1)

 result <- foreach(i=1:100,.combine=combine,.inorder=TRUE,.packages=c("data.table","plyr","Matrix","dplyr","xgboost$)) %dopar% {

   temp = unlist(p[i])
   index_1 = temp[1]
   index_2 = temp[2]
   v1 = unlist(group_list[index_1])
   v2 = unlist(group_list[index_2])
   v = append(v1,v2) 
   pg[i] = list(v)
   d = data[,v]

   x = data.table(d)
   trainMatrix <- x[,lapply(.SD,as.numeric)] %>% as.matrix
   out <- xgb.cv(data = trainMatrix, label = y, nrounds = 1000,objective = "binary:logistic",nthread = 4,eta=0.5,max_depth = 12,eval_metric="error",nfold = 10,prediction = TRUE,verbose = FALSE)  
   out$evaluation_log[5]$test_error_mean
 }
 stopCluster(c1)

foreach似乎无法正常工作

0 个答案:

没有答案