2013-09-23 21 views
2

我需要訪問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

任何其他想法使用?

回答

3

無需創建一個對象,你可以創建這樣一個列表:

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

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