我使用以下方式对我的数据运行了kmeans:
spherical_Data <- kmeans(myData,4)
现在计算我使用的dunn索引:
spherical_Data <- kmeans(myData,4)
Dist <- dist(myData,method="euclidean")
dunn(Dist, spherical_Data$cluster)
这里Dunn函数的第二个参数是一个包含myData中所有点的聚类成员资格的向量。
现在我按如下方式运行了核心kmeans:
kernel_Kmeans <- kkmeans(myData, centers=4, kernel = "rbfdot", kpar = "automatic")
kernel_Kmeans给出了以下输出:
Spectral Clustering object of class "specc"
Cluster memberships:
3 1 3 3 3 2 3 3 2 3 2 2 3 2 1 4 3 1 2 1 3 3 4 2 2 1 1 2 3 3 2 1 4 1 2 3 3 2 3 4 2 2 3 1 1 3 2 2 3 3 1 3 3 1 1 2 1 4 4 3 3 3 3 4 3 3 3 3 3 2 1 3 1 2 3 2 4 3 1 2 3 2 4 2 3 2 1 3 3 4 2 3 2 3 1 2 3 4 2 3 2 4 1 2 1 1 2 1 2 1 1 3 3 3 3 2 3 3 1 1 1 2 1 4 1 1 3 3 2 4 3 3 1 3 1 2 1 2 1 2 3 1 1 1 3 3 4 2 1 3 1 1 3 3 3 3 3 2 2
Gaussian Radial Basis kernel function.
Hyperparameter : sigma = 7.63469658003494
Centers:
[,1] [,2]
[1,] 0.03108416 -0.2142212
[2,] -0.63034038 -0.6909727
[3,] 0.69360916 0.3623118
[4,] -0.95418284 0.1941879
Cluster size:
[1] 287 209 389 115
Within-cluster sum of squares:
[1] 286.34824 27.35574 188.54685 158.99104
要计算Dunn索引,我需要第一个输出,即包含所有点的聚类成员资格的向量(在群集成员资格下标记)。
dunn(Dist, kernel_Kmeans$cluster) does not work.
有人可以告诉我这是怎么做的。
答案 0 :(得分:1)
这是一种从kkmeans
返回的对象中提取群集信息的方法。
一个例子:
library(kernlab)
data(iris)
sc <- kkmeans(as.matrix(iris[,-5]), centers=3)
输出(sc
):
Spectral Clustering object of class "specc"
Cluster memberships:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 3 2 3 2 3 2 3 3 3 3 2 3 2 3 3 2 3 2 3 2 2 2 2 2 2 2 3 3 3 3 2 3 2 2 3 3 3 3 2 3 3 3 3 3 3 3 3 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Gaussian Radial Basis kernel function.
Hyperparameter : sigma = 0.957009094923757
Centers:
[,1] [,2] [,3] [,4]
[1,] 5.006000 3.428000 1.462000 0.246000
[2,] 6.554286 2.974286 5.300000 1.865714
[3,] 5.580000 2.633333 3.986667 1.233333
Cluster size:
[1] 50 70 30
Within-cluster sum of squares:
[1] 1313.240 2004.637 625.704
您可以使用@.Data
来提取信息:
sc@.Data
# [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# [39] 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 3 2 3 2 3 2 3 3 3 3 2 3 2 3 3 2 3 2 3 2 2 2 2
# [77] 2 2 2 3 3 3 3 2 3 2 2 3 3 3 3 2 3 3 3 3 3 3 3 3 2 2 2 2 2 2 3 2 2 2 2 2 2 2
# [115] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2