Rのメソッドに関するアドバイスを使用して、クラスターの最適な数を決定し、後でさまざまな統計基準を使用してクラスターを説明することができます。クラスター分析の統計的基礎に関する基本的な知識を持ったRは初めてです。
クラスターの数を決定する方法:文献では、これを行うための一般的な方法の1つは、さまざまなクラスターソリューションの二乗差の合計(SSD)を比較するいわゆる「エルボー基準」です。したがって、SSDは分析のクラスター数に対してプロットされ、最適なクラスター数は、プロット内の「エルボー」を特定することによって決定されます(例:https://en.wikipedia.org/wiki/File:DataClustering_ElbowCriterion)。 JPG)この方法は、主観的な印象を与えるための最初のアプローチです。したがって、Rで実装したいと思います。これに関するインターネット上の情報はまばらです。ここに1つの良い例があります:http://www.mattpeeples.net/kmeans.htmlここで、作成者は興味深い反復アプローチを実行して、クラスタリングプロセスを数回繰り返した後、エルボーが何らかの形で安定しているかどうかを確認しました(ただし、階層型ではなくクラスターメソッドをパーティション化するためのものです)。文学の他の方法は、いわゆる「停止規則」を含みます。MILLIGAN&COOPERは、論文「データセット内のクラスター数を決定するための手順の検討」(http://link.springer.com/article/10.1007%2FBF02294245で入手可能)で、これらの停止規則の30を比較しました。 CalinskiとHarabaszの停止規則は、モンテカルロ評価で最良の結果をもたらしました。これをRに実装するための情報は、さらにまばらです。したがって、誰かがこれまたは別の停止ルール(または他の方法)を実装したことがある場合は、いくつかのアドバイスが非常に役立ちます。
クラスターを統計的に説明する:クラスターを説明するために、平均とある種の分散基準を使用することを考えました。私のデータは農地利用に関するものであり、自治体ごとのさまざまな作物の生産数を示しています。私の目的は、データセットで同様の土地利用パターンを見つけることです。
最初のテスト実行を行うために、オブジェクトのサブセット用のスクリプトを作成しました。これは次のようになります(スクリプト内の手順の説明、以下のソース)。
#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)
出典: