在 R 中的 PAM 聚类分析的平方和内计算

Compute within sum of squares from PAM cluster analysis in R

我正在使用 R 中的 PAM 进行聚类分析。我使用 vegdist() 计算了我的数据的 gower 距离,并使用 pam() 计算聚类变量效果很好。现在我需要一种方法来确定正确的 k。我知道的方法是直观比较不同ks的within squares sum。我如何从一系列 PAM 迭代中获取 WSS 以比较图中的总和,类似于 kmeans 的这个例子? http://rstudio-pubs-static.s3.amazonaws.com/137758_a80b40255fdd440ab76b41a646a6c482.html#loops

PAM 不优化 WSS。 WSS 是 k-means objective.

而是使用 PAM objective(在文献中可能称为 TD?)

objective 字段参见 ?[pam.object][1]

objective

the objective function after the first and second step of the pam algorithm.

请注意,与 WSS 类似,objective 应该随着 k 的增加而减少。因此你不能只选择最小值,但你应该在图中寻找膝盖。

因为 PAM 是随机的,您可能希望 运行 每个 k 多次,只保留最好的结果。