kmeans
对于 R {stats},我的 Ubuntu 机器的性能很糟糕,而 Windows 7 则没有问题。
X
是一个 5000 x 5 矩阵(数值变量)。
k
= 6
我的台式机是 Intel Xeon CPU W3530 @ 2.80GHz x 8(即 8 核)Dell Precision T3500,带有 Ubuntu 12.04.4 LTS(GNU/Linux 3.2.0-58-generic x86_64)和 24 GB RAM。
R 版本 3.0.2 (2013-09-25) -- "Frisbee Sailing" Copyright (C) 2013 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit)
> system.time(X.km <- kmeans(X, centers=k, nstart=25))
user system elapsed
49.763 52.347 103.426
与配备 Intel Core i5-2430M @ 2.40GHz、2 核、8 GB RAM、R 3.0.1 和相同数据的 Windows 7 64 位笔记本电脑相比:
> system.time(X.km <- kmeans(X, centers=k, nstart=25))
user system elapsed
0.36 0.00 0.37
快得多,快得多。对于nstart=1
问题仍然存在,我只是想放大执行时间。
我有什么明显的遗漏吗?
自己尝试一下,看看你达到了多少:
set.seed(101)
k <- 6
n <- as.integer(10)
el.time <- vector(length=n)
X <- matrix(rnorm(25000, mean=0.5, sd=1), ncol=5)
for (i in 1:n) { # sorry, not clever enough to vectorise
el.time[i] <- system.time(kmeans(X, centers=k, nstart=i))[[3]]
}
print(el.time)
plot(el.time, type="b")
我的结果(ubuntu机器):
> print(el.time)
[1] 0.056 0.243 0.288 0.489 0.510 0.572 0.623 0.707 0.830 0.846
Windows机器:
> print(el.time)
[1] 0.01 0.12 0.14 0.19 0.20 0.21 0.22 0.25 0.28 0.30