k均值:每次执行都具有相同的集群 [英] k-means: Same clusters for every execution
本文介绍了k均值:每次执行都具有相同的集群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能为特定数据集的每次执行获得相同的kmeans集群.就像随机值一样,我们可以使用固定种子.是否可以停止随机性进行聚类?
Is it possible to get same kmeans clusters for every execution for a particular data set. Just like for a random value we can use a fixed seed. Is it possible to stop randomness for clustering?
推荐答案
是.在进行聚类之前,使用set.seed
为随机值设置种子.
Yes. Use set.seed
to set a seed for the random value before doing the clustering.
使用kmeans
中的示例:
set.seed(1)
x <- rbind(matrix(rnorm(100, sd = 0.3), ncol = 2),
matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2))
colnames(x) <- c("x", "y")
set.seed(2)
XX <- kmeans(x, 2)
set.seed(2)
YY <- kmeans(x, 2)
测试是否相等:
identical(XX, YY)
[1] TRUE
这篇关于k均值:每次执行都具有相同的集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文