【R 层次聚类--hclust包】
http://blog.csdn.net/sherrymi/article/details/38341185
hclust(d, method = "complete", members=NULL)
d为距离矩阵。
method表示类的合并方法,有:
single 最短距离法
complete 最长距离法
median 中间距离法
mcquitty 相似法
average 类平均法
centroid 重心法
ward 离差平方和法
#'举例
d <- dist(x)
hc <- hclust(d,"single")
plot(hc)
#'然后可以用rect.hclust(tree, k = NULL, which = NULL, x = NULL, h = NULL,border = 2, cluster = NULL)来确定类的个数。 #'tree就是求出来的对象。k为分类的个数,h为类间距离的阈值。border是画出来的颜色,用来分类的。
rect.hclust(hc,k=2)
rect.hclust(hc,h=0.5)
#'提取每个样本所属的类别
label <- cutree(hc,k=2)
http://blog.csdn.net/sherrymi/article/details/38341185
hclust(d, method = "complete", members=NULL)
d为距离矩阵。
method表示类的合并方法,有:
single 最短距离法
complete 最长距离法
median 中间距离法
mcquitty 相似法
average 类平均法
centroid 重心法
ward 离差平方和法
#'举例
d <- dist(x)
hc <- hclust(d,"single")
plot(hc)
#'然后可以用rect.hclust(tree, k = NULL, which = NULL, x = NULL, h = NULL,border = 2, cluster = NULL)来确定类的个数。 #'tree就是求出来的对象。k为分类的个数,h为类间距离的阈值。border是画出来的颜色,用来分类的。
rect.hclust(hc,k=2)
rect.hclust(hc,h=0.5)
#'提取每个样本所属的类别
label <- cutree(hc,k=2)