我有一个非常大的数据集(5000 * 100),我想用kmeans
函数查找集群。但是,我不知道如何使用clusterApply
函数。如何在R中进行并行化k-均值?
set.seed(88)
mydata=rnorm(5000*100)
mydata=matrix(data=mydata,nrow = 5000,ncol = 100)
parallel.a=function(i) {
kmeans(mydata,3,nstart = i,iter.max = 1000)
}
library(parallel)
cl.cores <- detectCores()-1
cl <- makeCluster(cl.cores)
clusterSetRNGStream(cl,iseed=1234)
fit.km = clusterApply(cl,x,fun=parallel.a(500))
stopCluster(cl)
的clusterApply
需要“X”,我不知道如何设置值。另外,clusterApply
,和parLapply
之间有什么区别?非常感谢。
对不起,但它不重复。我正在使用'clusterApply'。 –
你可能想尝试'lowmemtkmeans'软件包。 – Henk