【问题标题】:how to create a cclust object given a dataframe of indices如何在给定索引数据框的情况下创建 clust 对象
【发布时间】:2013-09-28 20:02:10
【问题描述】:

我需要访问 R 中 cclust 包的函数 clustIndex。 函数原型如下:

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 对象并使用我的解决方案填充其变量的值,然后使用它。这会正确/有效吗? 包的文档可用here

还有其他想法可以使用吗?

【问题讨论】:

    标签: r matlab interface cluster-analysis


    【解决方案1】:

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

      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
    

    【讨论】:

    • 由于我对指数的内部程序知之甚少,这四个变量是否足以计算指数?
    • @AkashdeepSaluja 我编辑我的问题以添加一个示例。希望现在更清楚了。
    • 非常感谢,你救了我的命。 :)
    猜你喜欢
    • 2018-10-21
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-12
    • 2021-05-18
    相关资源
    最近更新 更多