不是你问的问题的确切答案,但也许你可能会考虑系列化而不是k-均值聚类。它有点像协调而不是聚类,但最终的结果是连续数据的热图,听起来与k-means后跟特定排序热图所显示的相似。
有r包系列化,叫seriation
,它有一个小插曲,你可以得到directly from CRAN
我会回答Q的细节一旦我编造了一个例子来试试。
好的 - 从上面的评论中正确的答案。首先一些虚拟数据 - 每个10个样本的3个群集,每个变量有3个。
set.seed(1)
dat <- data.frame(A = c(rnorm(10, 2), rnorm(10, -2), rnorm(10, -2)),
B = c(rnorm(10, 0), rnorm(10, 5), rnorm(10, -2)),
C = c(rnorm(10, 0), rnorm(10, 0), rnorm(10, -10)))
## randomise the rows
dat <- dat[sample(nrow(dat)),]
clus <- kmeans(scale(dat, scale = FALSE), centers = 3, iter.max = 50,
nstart = 10)
## means of n points in each cluster
mns <- sapply(split(dat, clus$cluster), function(x) mean(unlist(x)))
## order the data by cluster with clusters ordered by `mns`, low to high
dat2 <- do.call("rbind", split(dat, clus$cluster)[order(mns)])
## heatmaps
## original first, then reordered:
layout(matrix(1:2, ncol = 2))
image(1:3, 1:30, t(data.matrix(dat)), ylab = "Observations",
xlab = "Variables", xaxt = "n", main = "Original")
axis(1, at = 1:3)
image(1:3, 1:30, t(data.matrix(dat2)), ylab = "Observations",
xlab = "Variables", xaxt = "n", main = "Reordered")
axis(1, at = 1:3)
layout(1)
产量:什么
手段?用于聚类或其他变量的变量之一? – 2011-01-26 22:15:09
每个群集中的值的含义。例如,如果每个集群在data.frame中有30行,并且data.frame有10列,在这些列上执行k-means聚类,我想要在每个集群中使用300个值的均值。也可以使用质心。 – 2011-01-28 06:05:54