【发布时间】:2019-08-29 08:29:13
【问题描述】:
我正在尝试使用 levenshtein 距离使用 kmeans 聚类。我很难解释结果。
# courtesy: code is borrowed from the other thread listed below with some additions of k-means clustering
set.seed(1)
rstr <- function(n,k){ # vector of n random char(k) strings
sapply(1:n,function(i){do.call(paste0,as.list(sample(letters,k,replace=T)))})
}
str<- c(paste0("aa",rstr(10,3)),paste0("bb",rstr(10,3)),paste0("cc",rstr(10,3)))
# Levenshtein Distance
d <- adist(str)
rownames(d) <- str
hc <- hclust(as.dist(d))
plot(hc)
# to normalize the distances when there are unequal length sequences
max<- max(d)
data<- d/max
k.means.fit <- kmeans(data, 3)
library(cluster)
clusplot(d, k.means.fit$cluster, main='Clustering',
color=TRUE, shade=TRUE,
labels=5, lines=0, col.p = "dark green")
那么,集群图是什么,我该如何解释它?我提到了他们讨论的其他线程,这些线程集中在两个主要组件上。 https://stats.stackexchange.com/questions/274754/how-to-interpret-the-clusplot-in-r
但不清楚如何解释该图以及为什么这些点在那个椭圆/集群中?有任何想法吗?谢谢!!
【问题讨论】:
-
这可能更适合Cross Validated,因为看起来你已经有了代码,只需要帮助解释
-
很棒的评论,我发布了,还有没有办法用 k-means 绘制具有视觉吸引力的图形并绘制一些相关的点/模式?
-
视觉吸引力是主观的,什么是相关的取决于上下文,所以我不确定这些。但是有几篇关于 CV 的帖子可能会有所帮助,尤其是在他们的 pca 和 kmeans 标签中
-
@camille 请只推荐move(迁移)问题,不鼓励重复发布。谢谢。
-
K-means 需要一个连续数据矩阵作为输入,并且仅使用平方欧几里得,不是距离矩阵。虽然结果不会明显错误,但这种方法在形式上没有多大意义,因为这会产生各种偏见。添加新对象会更改现有对象的相似性等 - 不要这样做。仅在适当的数据矩阵上使用 KMeans,而不是距离矩阵。
标签: r cluster-analysis k-means levenshtein-distance unsupervised-learning