0

我正在尝试使用以下方法并行学习随机森林中的部分图:

cl <- makeCluster(detectCores()-1)
registerDoParallel(cl)

tmpp <- pdp::partial(rf_full, pred.var = c("Date", "AREA"), 
                     plot = T, plot.engine = "ggplot2",
                     parallel = T)

stopCluster(cl)

但是,我有这样的消息错误:

Error in summary.connection(connection) : invalid connection

如果它可以帮助,这里是错误消息的回溯如下:

16.
summary.connection(connection)
15.
summary(connection)
14.
serialize(data, node$con)
13.
sendData.SOCKnode(con, list(type = type, data = value, tag = tag))
12.
sendData(con, list(type = type, data = value, tag = tag))
11.
postNode(con, "EXEC", list(fun = fun, args = args, return = return, tag = tag))
10.
sendCall(cl[[i]], fun, list(...))
9.
clusterCall(cl, workerInit, c.expr, exportenv, pkgname, packages, attachExportEnv)
8.
e$fun(obj, substitute(ex), parent.frame(), e$data)
7.
foreach::`%dopar%`(fe, do.ply(i))
6.
llply(.data = .data, .fun = .fun, ..., .progress = .progress, .inform = .inform, .parallel = .parallel, .paropts = .paropts)
5.
ldply(.data = pieces, .fun = .fun, ..., .progress = .progress, .inform = .inform, .parallel = .parallel, .paropts = .paropts, .id = .id)
4.
plyr::adply(pred.grid, .margins = 1, .progress = progress, .parallel = parallel, .paropts = paropts, .fun = function(x) { temp <- train temp[, pred.var] <- x ...
3.
getParDepReg(object, pred.var = pred.var, pred.grid = pred.grid, inv.link = inv.link, ice = ice, train = train, progress = progress, parallel = parallel, paropts = paropts, ...)
2.
partial.default(rf_full, pred.var = c("Date", "AREA"), plot = T, plot.engine = "ggplot2", parallel = T, paropts = list(.packages = "randomForest"))
1.
pdp::partial(rf_full, pred.var = c("Date", "AREA"), plot = T, plot.engine = "ggplot2", parallel = T, paropts = list(.packages = "randomForest")

注意:我在使用这种方式进行并行化之前学习了我的 RF,并且它可以工作。

这是我的会话信息:

> sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    
system code page: 1250

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

other attached packages:
 [1] doParallel_1.0.16   iterators_1.0.13    foreach_1.5.1       ggpubr_0.4.0       
 [5] forcats_0.5.0       stringr_1.4.0       dplyr_1.0.0         purrr_0.3.4        
 [9] readr_1.3.1         tidyr_1.1.0         tibble_3.0.4        ggplot2_3.3.2      
[13] tidyverse_1.3.0     pdp_0.7.0           MLmetrics_1.1.1     rpart_4.1-15       
[17] randomForest_4.6-14

loaded via a namespace (and not attached):
 [1] httr_1.4.2        jsonlite_1.7.1    carData_3.0-4     modelr_0.1.8     
 [5] assertthat_0.2.1  blob_1.2.1        renv_0.12.3       cellranger_1.1.0 
 [9] yaml_2.2.1        pillar_1.4.6      backports_1.1.8   lattice_0.20-41  
[13] glue_1.4.2        digest_0.6.27     ggsignif_0.6.0    rvest_0.3.6      
[17] colorspace_1.4-1  plyr_1.8.6        cowplot_1.1.1     htmltools_0.5.1.1
[21] pkgconfig_2.0.3   broom_0.7.0       haven_2.3.1       bookdown_0.20    
[25] scales_1.1.1      openxlsx_4.2.3    rio_0.5.16        farver_2.0.3     
[29] generics_0.0.2    car_3.0-10        ellipsis_0.3.1    withr_2.3.0      
[33] cli_2.1.0         magrittr_1.5      crayon_1.3.4      readxl_1.3.1     
[37] evaluate_0.14     fs_1.4.2          fansi_0.4.1       rstatix_0.6.0    
[41] xml2_1.3.2        foreign_0.8-80    tools_4.0.4       data.table_1.13.6
[45] hms_0.5.3         lifecycle_0.2.0   munsell_0.5.0     reprex_0.3.0     
[49] zip_2.1.1         compiler_4.0.4    tinytex_0.26      rlang_0.4.10     
[53] grid_4.0.4        rstudioapi_0.11   labeling_0.4.2    rmarkdown_2.5    
[57] codetools_0.2-16  gtable_0.3.0      abind_1.4-5       DBI_1.1.0        
[61] curl_4.3          R6_2.4.1          gridExtra_2.3     lubridate_1.7.9  
[65] knitr_1.30        stringi_1.4.6     Rcpp_1.0.5        vctrs_0.3.4      
[69] dbplyr_1.4.4      tidyselect_1.1.0  xfun_0.18
4

0 回答 0