2016-08-29 97 views
0

我已经在R中使用不同的聚类方法(kmeans,hclust,agnes,funny)对风暴能量数据进行聚类,但即使很容易为我的工作选择最佳方法,但我需要一种计算(而不是理论)方法,通过它们的结果来比较和评估方法。你相信有什么东西吗?在R中聚类海浪数据

由于提前,

+0

我记得有人使用Dunn索引来评估聚类算法。见http://artax.karlin.mff.cuni.cz/r-help/library/clValid/html/dunn.html –

+2

嗨。也许最好在Cross Validated上提出你的问题,这是关于机器学习等问题的平台。如果您正在寻找R中的软件包进行集群,请尝试使用插入符号包。 caret包含许多用标准包装进行聚类的不同方法,因此比较结果更容易。 – PhiSeu

+0

感谢您的建议,我会仔细研究以上! – Marz

回答

0

谢谢你的问题,我学到了你不能从factoextra

使用kmeans演示从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) 

enter image description here计算使用eclust功能集群的最佳数目

enter image description here

聚类功能比较:

您可以使用所有可用的方法和计算集群的最佳数目与:

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 

间隙统计即优度配合措施:

“差距统计量”用作聚类算法的拟合优度的度量,参见paper

对于固定数量的用户定义的簇,我们可以从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每个算法的间隙统计量= 1至5.列3,gapStat_at_chosenCluster在k = 5簇处具有 间隙统计量。统计越低,分区越好,因此,在k = 5个簇中,kmeans相对于USArrests数据集执行更好的

+0

感谢您的回答,但我认为您提出了另一种制作群集的方法(某事我已经完成了)。这也是固定的,我需要5个群集,所以我没有寻找最佳数量的群集。除非有意义运行此代码才能找到5个集群更好的方法! – Marz