我有一個非常大的數據集(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