r - Error in { : task 1 failed - "could not find function "knn"" -
i trying run parallel knn program on r error:
error in { : task 1 failed - "could not find function "knn""
this program:
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)
you need call library(class) on each of nodes. foreach makes easy via .packages argument.
system.time(foreach( icount(countrows), .packages="class" ) %dopar% { summary(knn(train, test, cl, k=25, prob = true)) }) you might need export train, test, , cl.
system.time( foreach( icount(countrows), .packages="class", .export=c("train","test","cl") ) %dopar% { summary(knn(train, test, cl, k=25, prob = true)) } )
Comments
Post a Comment