{:任务1失败 - “无法找到功能”knn“”出错

时间:2015-11-01 14:41:21

标签: r windows parallel-processing knn

我正在尝试在R上运行并行kNN程序,但是我收到了这个错误:

{:任务1失败 - “无法找到功能”knn“”

出错

这是该计划:

library(class)
library(doSNOW)
library(foreach)

train <- read.csv('train.csv')
test <- read.csv('test.csv')
trainY <- read.csv('trainY.csv')
cl <- as.vector(as.matrix(trainY))

system.time(summary(knn(train, test, cl, k=25, prob = TRUE)))


clus <- makeCluster(4)
registerDoSNOW(clus)
countrows=nrow(test)

system.time(foreach( icount(countrows) ) %dopar% {
  summary(knn(train, test, cl, k=25, prob = TRUE))
})

stopCluster(clus)

1 个答案:

答案 0 :(得分:5)

您需要在每个节点上调用library(class)foreach通过.packages参数轻松实现这一点。

system.time(foreach( icount(countrows), .packages="class" ) %dopar% {
  summary(knn(train, test, cl, k=25, prob = TRUE))
})

您可能还需要导出traintestcl

system.time(
  foreach( icount(countrows), .packages="class",
           .export=c("train","test","cl") ) %dopar% {
    summary(knn(train, test, cl, k=25, prob = TRUE))
  }
)