4

尝试使用从包foreach中绘制部分依赖图。randomForest得到错误:

Error in { : task 1 failed - undefined columns selected

 library(randomForest)
 library(DoParallel)
 library(mlbench)
 data(Sonar)
 registerDoParallel(8,cores=8)

Sonar.rrf <- randomForest(
Sonar[-61],
Sonar[[61]],
ntree = 101,
oob.prox = FALSE,
importance = TRUE
)

Sonarimp <- importance(Sonar.rrf)

m.list <- foreach(
i = 1:10,
.combine = 'partialPlot',
.init = NULL,
.multicombine = TRUE,
.inorder = FALSE,
.packages = 'randomForest'
) %dopar%
{
impvar <- rownames(Sonarimp)[order(Sonarimp[, 1], decreasing = TRUE)]
imptvar <- impvar[i]
partialPlot(
  x = Sonar.rrf,
  pred.data = Sonar,
  x.var = imptvar,
  which.class = "R",
  xlab = imptvar,
  main = paste("Partial Dependence on", imptvar),
  ylim = c(30, 70)
)
}
4

0 回答 0