2

I need to access a function clustIndex of cclust package in R. The protoptype of the function is as follows:

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 is the object that is produced from function cclust in the same package, but I have a clustering algorithm coded in Matlab, and want to use this function clustIndex to calculate the indices using the solution produced by the algorithm in matlab.

One way I can think of is to create an object of cclust and fill value of its variable using my solutuion and then use it. Will this be correct/work? Documentation of the package is available here

Any other ideas to use?

4

1 回答 1

4

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

  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
于 2013-09-23T19:55:40.010 回答