R: Hierarchical Cluster 层次聚类

构造数据:

> dataset = matrix(c(1,2,
+ 1.2,2,
+ 8,9,
+ 0.9,1.8,
+ 7,10,
+ 8.8,9.2), nrow=6, byrow=T)
> dataset
     [,1] [,2]
[1,]  1.0  2.0
[2,]  1.2  2.0
[3,]  8.0  9.0
[4,]  0.9  1.8
[5,]  7.0 10.0
[6,]  8.8  9.2


聚类:

> d = dist(dataset)
> d
           1          2          3          4          5
2  0.2000000                                            
3  9.8994949  9.7590983                                 
4  0.2236068  0.3605551 10.1118742                      
5 10.0000000  9.8812955  1.4142136 10.2200783           
6 10.6150836 10.4690019  0.8246211 10.8245092  1.9697716
> hclust(d, method = "complete")

Call:
hclust(d = d, method = "complete")

Cluster method   : complete 
Distance         : euclidean 
Number of objects: 6 

> hc = hclust(d, method = "complete")
> plot(hc)




分成两个簇:

> democut<-cutree(hc,k=2)
> democut
[1] 1 1 2 1 2 2

参考:

http://www.r-tutor.com/gpu-computing/clustering/hierarchical-cluster-analysis
http://stat.ethz.ch/R-manual/R-devel/library/stats/html/hclust.html
http://ecology.msu.montana.edu/labdsv/R/labs/lab13/lab13.html










转载于:https://my.oschina.net/letiantian/blog/324395

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值