私は、Rの異なるクラスタリング手法(kmeans、hclust、agnes、funny)を使用して嵐のエネルギーデータをクラスタリングしていますが、自分の仕事に最適な方法を選択するのが簡単でも、それらの結果を介してメソッドを比較して評価するための計算上の(理論ではない)メソッドです。あなたは何かがあると信じますか?事前に海洋波データのクラスタリングR
おかげで、質問の
私は、Rの異なるクラスタリング手法(kmeans、hclust、agnes、funny)を使用して嵐のエネルギーデータをクラスタリングしていますが、自分の仕事に最適な方法を選択するのが簡単でも、それらの結果を介してメソッドを比較して評価するための計算上の(理論ではない)メソッドです。あなたは何かがあると信じますか?事前に海洋波データのクラスタリングR
おかげで、質問の
おかげで、私はあなたがhere
# Load and scale the dataset
data("USArrests")
DF <- scale(USArrests)
When data is not scaledd the clustering results might not be reliable [example](http://stats.stackexchange.com/questions/140711/why-does-gap-statistic-for-k-means-suggest-one-cluster-even-though-there-are-ob)
library("factoextra")
# Enhanced k-means clustering
res.km <- eclust(DF, "kmeans")
# Gap statistic plot
fviz_gap_stat(res.km$gap_stat)
から
kmeans
デモを使用してfactoextra
パッケージ
からeclust
機能を使用してクラスターの最適数を計算することができることを学びました
012クラスタリング機能の
比較:
あなたはすべての利用可能なメソッドを使用してクラスターの最適数を計算することができます
clusterFuncList = c("kmeans", "pam", "clara", "fanny", "hclust", "agnes" ,"diana")
resultList <- sapply(clusterFuncList,function(x) {
cat("Begin clustering for function:",x,"\n")
#For each clustering function find optimal number of clusters, to disable plotting use graph=FALSE
clustObj = eclust(DF, x,graph=FALSE)
#return optimal number of clusters for each clustering function
cat("End clustering for function:",x,"\n\n\n")
resultDF = data.frame(clustFunc = x, optimalNumbClusters = clustObj$nbclust,stringsAsFactors=FALSE)
})
# >resultList
# clustFunc optimalNumbClusters
# 1 kmeans 4
# 2 pam 4
# 3 clara 5
# 4 fanny 5
# 5 hclust 4
# 6 agnes 4
# 7 diana 4
ギャップ統計すなわち適合度の指標:
「ギャップ統計」は、クラスタリングアルゴリズムの適合度の尺度として使用されます(を参照)。我々はcluster
パッケージからclusGap
機能と各クラスタリングアルゴリズムのギャップ統計量を比較することができ、ユーザ定義されたクラスタの固定数について
:
numbClusters = 5
library(cluster)
clusterFuncFixedK = c("kmeans", "pam", "clara", "fanny")
gapStatList <- do.call(rbind,lapply(clusterFuncFixedK,function(x) {
cat("Begin clustering for function:",x,"\n")
set.seed(42)
#For each clustering function compute gap statistic
gapStatBoot=clusGap(DF,FUNcluster=get(x),K.max=numbClusters)
gapStatVec= round(gapStatBoot$Tab[,"gap"],3)
gapStat_at_AllClusters = paste(gapStatVec,collapse=",")
gapStat_at_chosenCluster = gapStatVec[numbClusters]
#return gap statistic for each clustering function
cat("End clustering for function:",x,"\n\n\n")
resultDF = data.frame(clustFunc = x, gapStat_at_AllClusters = gapStat_at_AllClusters,gapStat_at_chosenCluster = gapStat_at_chosenCluster, stringsAsFactors=FALSE)
}))
# >gapStatList
# clustFunc gapStat_at_AllClusters gapStat_at_chosenCluster
#1 kmeans 0.184,0.235,0.264,0.233,0.27 0.270
#2 pam 0.181,0.253,0.274,0.307,0.303 0.303
#3 clara 0.181,0.253,0.276,0.311,0.315 0.315
#4 fanny 0.181,0.23,0.313,0.351,0.478 0.478
上記の表は、= kから各clutserで各アルゴリズムのギャップ統計量を有しています第3欄、gapStat_at_chosenCluster
は、k = 5クラスタで のギャップ統計値を有する。統計下部したがって仕切り良好、USArrests
セット
あなたの答えをありがとうが、私はあなたがクラスタを作る別の方法を提案していると思います。また、私は5つのクラスタが必要であると固定されているので、最適な数のクラスタを探しているわけではありません。 5つのクラスターでどのメソッドがうまく機能するかを見つけるためにこのコードを実行する意味がある場合を除いて! – Marz
にK他のアルゴリズムへ= 5クラスタ、
kmeans
行うより良い相対的でIは、クラスタリングアルゴリズムを評価するために、ダンインデックスを使用して誰かを覚え。 http://artax.karlin.mff.cuni.cz/r-help/library/clValid/html/dunn.html –こんにちは。おそらく、クロスバリデーションについて質問する方が良いかもしれません。これは、機械学習に関する質問のプラットフォームであり、スタック交換からです。クラスタリングのためにRのパッケージを探している場合は、キャレットパッケージを試してみてください。キャレットには、標準化されたラッパーを使用してクラスタリングするためのさまざまなメソッドが多数含まれているため、結果を比較するのが簡単です。 – PhiSeu
あなたの提案をありがとう、私は慎重に上記を勉強します! – Marz