Hierarchy-based clustering----Agnes algorithm using (R language)

Source: Internet
Author: User
Tags require

Condensation

# Generate DataSet X<-c (Rnorm (200,30,1), Rnorm (200,10,1.5), Rnorm (100,5,0.5)) y<-c (Rnorm (200,30,1), Rnorm (200,10,1.5), Rnorm (100,5,0.5)) data<-data.frame (x, y) # color space Library (colorspace) # shows the structure of the dataset str (data) # System Clustering # Some of the necessary functions of clustering library (CLU
ster) Library (rattle) #系统聚类函数在包amap中 require (AMAP, quietly=true) #聚类结果有包fpc提供 require (FPC, quietly=true) #绘图 need CBA bag Require (CBA, quietly=true) #method曼哈顿距离, Ward Deviation squared and Chcluster <-hclusterpar (Na.omit (Data[,c (1:2)]), method= " Manhattan ", link=" Ward ", nbproc=2) Chcluster # Cluster Center Centers.hclust (Na.omit (Data[,c (1:2)]), Chcluster, 3) #产生树形图 rectangular display of cluster junctions Fruit par (bg= "grey") plot (Chcluster, main= "", sub= "", xlab= "", Labels=false, hang=0) rect.hclust (Chcluster, k=3) #加标题 title (m Ain= "Hcluster_dendrogram_data", Sub=paste ("R", Format (Sys.time (), "%y-%b-%d%h:%m:%s"), Sys.info () ["User"]) # Correlation between classes and classes par (bg= "yellow") Plotcluster (Na.omit (Data[,c (1:2)]), Cutree (Chcluster, 3)) title (main= "discriminant Coordinates data ", Sub=paste (" R ", Format (Sys.time (),"%y-%b-%d%h:%m:%s "),Sys.info () ["User"]) #数据集的聚类效果图 plot (Data[,c (1:2)], Col=cutree (Chcluster, 3)) title (main= "", Sub=paste ("R", Format ( Sys.time (), "%y-%b-%d%h:%m:%s"), Sys.info () ["User"]) #验证聚类结果的基本统计信息 cluster.stats (Dist (Na.omit (1:2))), Cutree (Chcluster, 3)) #输出结果 Result<-cbind (Data,cutree (chcluster,3)) write.csv (result, "cengciresult.csv")


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.