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

Jos*_*chi 12 r cluster-analysis data-mining

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

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

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

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

    #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)
Run Code Online (Sandbox Code Playgroud)

资料来源:

Ano*_*sse 7

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

但是你的问题标题提到了层次聚类,你的代码也是如此?

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

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

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

  • 只看树状图的顶部.关键是,你想看看是否有一个明确的门槛.如果树形图在顶部没有大步,那么它并不重要.SSD无法捕获这个,因为它测试*一个*特定的水平切割,而不是是否有充分的理由选择此切割. (2认同)

Ger*_*ine 7

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