R:数据分析之聚类分析hclust
标签:
it |
分类: R |
> x=runif(10)
>
y=runif(10)
> S=cbind(x,y)
#得到2维的数组
>
rownames(S)=paste("Name",1:10,"")
#赋予名称,便于识别分类
>
out.dist=dist(S,method="euclidean")
#数值变距离
注释:在聚类中求两点的距离有:
1,绝对距离:manhattan
2,欧氏距离:euclidean 默认
3,闵科夫斯基距离:minkowski
4,切比雪夫距离:chebyshev
5,马氏距离:mahalanobis
6,蓝氏距离:canberra
>
out.hclust=hclust(out.dist,method="complete") #根据距离聚类
注释:聚类中集合之间的距离:
1,类平均法:average
2,重心法:centroid
3,中间距离法:median
4,最长距离法:complete 默认
5,最短距离法:single
6,离差平方和法:ward
7,密度估计法:density
> plclust(out.hclust)
#对结果画图 如图1
>
rect.hclust(out.hclust,k=3)
#用矩形画出分为3类的区域 如图2
>
out.id=cutree(out.hclust,k=3)
#得到分为3类的数值
> out.id
>
table(out.id,paste("Name",1:10,""))
#以向量的方式分辨名称对应的类
out.id Name 1 Name 10 Name
2 Name 3 Name 4
Name 5 Name 6
Name 7
out.id Name 8 Name 9
http://s12/middle/615770bdhc52bb78c635b&690

加载中…