如何创建给定指数的

问题描述:

我需要访问cclust封装的功能clustIndex在R. 的数据帧的函数的protoptype是如下一个cclust对象:如何创建给定指数的

clustIndex (y, x, index = "all") 
y Object of class "cclust" returned by a clustering algorithm such as kmeans 
x Data matrix where columns correspond to variables and rows to observations 
index The indexes that are calculated "calinski", "cindex", "db", "hartigan", 
     "ratkowsky", "scott", "marriot", "ball", "trcovw", "tracew", "friedman", 
     "rubin", "ssi", "likelihood", and "all" for all the indexes. Abbreviations 
     of these names are also accepted. 

y是作为对象由函数cclust在同一个包中生成,但我有一个在Matlab中编码的聚类算法,并且希望使用该函数clustIndex来使用matlab中的算法产生的解来计算索引。

我能想到的一种方法是创建一个cclust对象,并使用我的solutuion填充其变量的值,然后使用它。这是正确的/工作吗? 包装文件是可用here

任何其他想法使用?

无需创建一个对象,你可以创建这样一个列表:

y = list(cluster = matlabObj$cluster , 
      centers = matlabObj$centers , 
      withins = matlabObj$withins, 
      size = matlabObj$size) 

这里使用cclust(你应该在这里使用MATLAB集群),以表明该4个变量是足够的一个实例使用clustIndex功能:

x<- rbind(matrix(rnorm(100,sd=0.3),ncol=2), 
     matrix(rnorm(100,mean=1,sd=0.3),ncol=2)) 
matlabObj <- cclust(x,2,20,verbose=TRUE,method="kmeans") 
clustIndex(matlabObj,x, index="all") 

y = list(cluster = matlabObj$cluster , 
     centers = matlabObj$centers , 
     withins = matlabObj$withins, 
     size = matlabObj$size) 

identical(clustIndex(y,x, index="all"), 
      clustIndex(matlabObj,x, index="all")) 

[1] TRUE 
+0

由于我很少意识到指数的内部程序,这四个变量是否足以计算指数? –

+0

@AkashdeepSaluja我编辑我的问题添加一个例子。希望现在更清楚。 – agstudy

+0

非常感谢,你救了我的命。 :) –