我需要一些关于R中确定最佳聚类数的方法的建议,以及使用不同统计标准描述聚类的方法。我对R是新手,只有基本的聚类分析统计基础知识。
1. 确定聚类数的方法: 文献中常用的方法之一是所谓的“拐点准则”,该方法比较不同聚类解的平方差和(SSD)。因此,将SSD绘制在分析中的聚类数量上,并通过识别图表中的“拐点”来确定最佳聚类数(例如:这里:https://en.wikipedia.org/wiki/File:DataClustering_ElbowCriterion.JPG)。这种方法是获取主观印象的第一步。因此,我想在R中实现它。网络上关于这个的信息很少。这里有一个很好的例子:http://www.mattpeeples.net/kmeans.html,作者还进行了有趣的迭代方法,看看拐点是否在聚类过程的多次重复后保持稳定(尽管它是针对划分聚类方法而不是层次聚类)。 文献中的其他方法包括所谓的“停止规则”。MILLIGAN和COOPER在他们的论文“An examination of procedures for determining the number of clusters in a data set”(可在此处获取:http://link.springer.com/article/10.1007%2FBF02294245)中比较了30种这样的停止规则,发现Calinski和Harabasz的停止规则在蒙特卡罗评估中提供了最佳结果。在R中实现它的信息甚至更少。 因此,如果有人曾经实施过这个或其他停止规则(或其他方法),一些建议将非常有帮助。
2. 描述聚类的统计学方法: 为了描述聚类,我考虑使用平均值和某种方差准则。我的数据是关于农业土地利用的,显示每个市镇不同作物的产量数据。我的目标是在数据集中找到相似的土地利用模式。
1. 确定聚类数的方法: 文献中常用的方法之一是所谓的“拐点准则”,该方法比较不同聚类解的平方差和(SSD)。因此,将SSD绘制在分析中的聚类数量上,并通过识别图表中的“拐点”来确定最佳聚类数(例如:这里:https://en.wikipedia.org/wiki/File:DataClustering_ElbowCriterion.JPG)。这种方法是获取主观印象的第一步。因此,我想在R中实现它。网络上关于这个的信息很少。这里有一个很好的例子:http://www.mattpeeples.net/kmeans.html,作者还进行了有趣的迭代方法,看看拐点是否在聚类过程的多次重复后保持稳定(尽管它是针对划分聚类方法而不是层次聚类)。 文献中的其他方法包括所谓的“停止规则”。MILLIGAN和COOPER在他们的论文“An examination of procedures for determining the number of clusters in a data set”(可在此处获取:http://link.springer.com/article/10.1007%2FBF02294245)中比较了30种这样的停止规则,发现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)
参考来源:
- http://www.r-tutor.com/gpu-computing/clustering/distance-matrix (关于距离矩阵的应用)
- (如何使用R进行层次或k-means聚类分析)
- http://statistics.berkeley.edu/classes/s133/Cluster2a.html (关于聚类分析,包括k-means和层次聚类等)