检索R中的最佳簇数

tea*_*eef 10 statistics r cluster-analysis machine-learning

我有数据,我想根据Gap统计数据评估最佳簇数.

我在r中读取了gap statistics的页面,它提供了以下示例:

gs.pam.RU <- clusGap(ruspini, FUN = pam1, K.max = 8, B = 500)
gs.pam.RU
Run Code Online (Sandbox Code Playgroud)

当我打电话时gs.pam.RU.Tab,我明白了

Clustering Gap statistic ["clusGap"].
B=500 simulated reference sets, k = 1..8
 --> Number of clusters (method 'firstSEmax', SE.factor=1): 4
         logW   E.logW         gap     SE.sim
[1,] 7.187997 7.135307 -0.05268985 0.03729363
[2,] 6.628498 6.782815  0.15431689 0.04060489
[3,] 6.261660 6.569910  0.30825062 0.04296625
[4,] 5.692736 6.384584  0.69184777 0.04346588
[5,] 5.580999 6.238587  0.65758835 0.04245465
[6,] 5.500583 6.119701  0.61911779 0.04336084
[7,] 5.394195 6.016255  0.62205988 0.04243363
[8,] 5.320052 5.921086  0.60103416 0.04233645
Run Code Online (Sandbox Code Playgroud)

我想从中检索簇的数量.但是,与能够轻松获得此数字的pamk函数相反,我找不到使用clusGap获取此数字的方法.

然后我尝试使用该maxSE函数,但我不知道参数f和SE.f代表什么或我如何从数据矩阵中获取它们.

有没有简单的方法来检索这个最佳数量的集群?

jlh*_*ard 9

答案在输出中:

...
 --> Number of clusters (method 'firstSEmax', SE.factor=1): 4
...
Run Code Online (Sandbox Code Playgroud)

这是产生最大值的簇的数量gap(在表的第4行).

该参数maxSE(...)gapSE.sim分别为:

with(gs.pam.RU,maxSE(Tab[,"gap"],Tab[,"SE.sim"]))
# [1] 4
Run Code Online (Sandbox Code Playgroud)

绘图有时很有用gap,看看群集选项有多么不同:

plot(gs.pam.RU)
gap.range <- range(gs.pam.RU$Tab[,"gap"])
lines(rep(which.max(gs.pam.RU$Tab[,"gap"]),2),gap.range, col="blue", lty=2)
Run Code Online (Sandbox Code Playgroud)