首页 文章

分层聚类:确定最佳聚类数并统计描述聚类

提问于
浏览
12

我可以对R中的方法使用一些建议来确定最佳簇数,然后用不同的统计标准描述簇 . 我是R的新手,具有关于聚类分析统计基础的基本知识 .

  • Methods to determine the number of clusters: 在文献中,一种常用的方法是所谓的"Elbow-criterion",它比较不同群集解决方案的平方差异和(SSD) . 因此,SSD在分析中针对Cluster的数量绘制,并且通过识别图中的“肘”来确定最佳簇数(例如,这里:https://en.wikipedia.org/wiki/File:DataClustering_ElbowCriterion.JPG) . 该方法是获得主观印象的第一种方法 . 因此,我想在R中实现它 . 互联网上的信息很少 . 这里有一个很好的例子:http://www.mattpeeples.net/kmeans.html其中作者也做了一个有趣的迭代方法,看看在多次重复聚类过程之后肘是否在某种程度上是稳定的(尽管它是用于分区聚类方法而不是分层) . 文献中的其他方法包括所谓的“停止规则” . MILLIGAN&COOPER在他们的论文“检查确定数据集中簇数的程序”(此处为:http://link.springer.com/article/10.1007%2FBF02294245)中发现Calinski和Harabasz的停止规则在Monte中提供了最佳结果时,将这些停止规则中的30个进行了比较卡罗评价 . 在R中实现这一点的信息甚至更为稀疏 . 因此,如果有人曾经实施过这个或另一个停止规则(或其他方法),那么一些建议会非常有用 .

  • Statistically describe the clusters :为了描述我想到的使用均值和某种方差标准的聚类 . 我的数据是关于农业用地的数据,并显示每个市的不同作物的产量数量 . 我的目标是在我的数据集中找到类似的土地利用模式 .

我为一个对象子集生成了一个脚本来进行第一次测试运行 . 它看起来像这样(脚本中的步骤解释,下面的来源) .

#Clusteranalysis agriculture

    #Load data
    agriculture <-read.table ("C:\\Users\\etc...", header=T,sep=";")
    attach(agriculture)

    #Define Dataframe to work with
    df<-data.frame(agriculture)

    #Define a Subset of objects to first test the script
    a<-df[1,]
    b<-df[2,]
    c<-df[3,]
    d<-df[4,]
    e<-df[5,]
    f<-df[6,]
    g<-df[7,]
    h<-df[8,]
    i<-df[9,]
    j<-df[10,]
    k<-df[11,]
    #Bind the objects
    aTOk<-rbind(a,b,c,d,e,f,g,h,i,j,k)

    #Calculate euclidian distances including only the columns 4 to 24
    dist.euklid<-dist(aTOk[,4:24],method="euclidean",diag=TRUE,upper=FALSE, p=2)
    print(dist.euklid)

    #Cluster with Ward
    cluster.ward<-hclust(dist.euklid,method="ward")

    #Plot the dendogramm. define Labels with labels=df$Geocode didn't work
    plot(cluster.ward, hang = -0.01, cex = 0.7)

    #here are missing methods to determine the optimal number of clusters

    #Calculate different solutions with different number of clusters
    n.cluster<-sapply(2:5, function(n.cluster)table(cutree(cluster.ward,n.cluster)))
    n.cluster

    #Show the objects within clusters for the three cluster solution
    three.cluster<-cutree(cluster.ward,3)
    sapply(unique(three.cluster), function(g)aTOk$Geocode[three.cluster==g])

    #Calculate some statistics to describe the clusters
    three.cluster.median<-aggregate(aTOk[,4:24],list(three.cluster),median)
    three.cluster.median
    three.cluster.min<-aggregate(aTOk[,4:24],list(three.cluster),min)
    three.cluster.min
    three.cluster.max<-aggregate(aTOk[,4:24],list(three.cluster),max)
    three.cluster.max
    #Summary statistics for one variable
    three.cluster.summary<-aggregate(aTOk[,4],list(three.cluster),summary)
    three.cluster.summary

    detach(agriculture)

Sources

3 回答

  • 6

    所示链接的肘部标准适用于 k-means . 群集均值显然与k均值相关,并且不适合于链接聚类(特别是不适用于单链接,参见单链接效应) .

    你的问题 Headers 提到 hierarchical clustering ,你的代码也是如此?

    请注意,弯头标准不会选择最佳簇数 . 它选择 k-means clusters 的最佳数量 . 如果使用其他群集方法,则可能需要不同数量的群集 .

    no such thing as the objectively best clustering . 因此,也没有客观上最好的簇数 . k-means有一个经验法则,它选择群集数量和最小化目标函数之间的(可能是最好的)权衡(因为增加群集的数量总是可以改善目标函数);但这主要是为了对抗k均值的赤字 . 这绝不是客观的 .

    聚类分析本身不是一项客观任务 . 聚类在数学上可能是好的,但是没用 . 聚类可能在数学上得分更差,但它可能为您提供无法用数学方法测量的数据 .

  • 1

    这是一个非常晚的答案,可能对提问者不再有用 - 但也许对其他人有用 . 查看包NbClust . 它包含26个索引,可以为您提供建议的聚类数(您也可以选择聚类类型) . 您可以通过这样的方式运行它以获得所有索引的结果,然后您基本上可以使用大多数索引推荐的聚类数 . 是的,我认为基本统计数据是描述集群的最佳方式 .

  • 3

    您也可以尝试R-NN曲线方法 . http://rguha.net/writing/pres/rnn.pdf

相关问题