在 R 中聚类时从 ClusGap 获取 K

Get K from ClusGap when clustering in R

我想使用 clusgap 来估计给定数据集所需的聚类数。问题是我无法从 clusgap 获得 k 值,尽管这个库被推荐用于间隙统计。

以下是我如何使用 clusgap:

hcluster = clusGap(dataMatrix,  FUN = hcut, nstart = 25, K.max = 100, B = 50)
kcluster = clusGap(dataMatrix, kmeans, K.max=100, B=50)

以下是 clusgaps 输出,我可以看到推荐的簇数是 11,但我无法动态访问这个数字。

Clustering Gap statistic ["clusGap"] from call:
clusGap(x = dataMatrix, FUNcluster = hcut, K.max = 100, B = 50,     nstart = 25)
B=50 simulated reference sets, k = 1..100; spaceH0="scaledPCA"
 --> Number of clusters (method 'firstSEmax', SE.factor=1): 11
           logW    E.logW      gap      SE.sim
  [1,] 8.995981 10.000102 1.004121 0.004184801
  [2,] 8.694404  9.716407 1.022003 0.017857009
  [3,] 8.538334  9.616808 1.078473 0.008792356
  [4,] 8.466726  9.574631 1.107905 0.005905742
  [5,] 8.363253  9.550745 1.187492 0.004978537
  [6,] 8.303085  9.531952 1.228867 0.004084501
  [7,] 8.270890  9.516404 1.245514 0.004118244
  [8,] 8.241259  9.502743 1.261484 0.004018474
  [9,] 8.220926  9.490543 1.269617 0.003874152

如有任何帮助,我们将不胜感激。

万一有人遇到这个,我是这样做的:

hcluster = clusGap(dataMatrix,  FUN = hcut, nstart = 25, K.max = 100, B = 50)    
k <- maxSE(hcluster$Tab[, "gap"], hcluster$Tab[, "SE.sim"], method="Tibs2001SEmax")