Clustering analysis based on R

Source: Internet
Author: User

A data set

SETWD ("C://users//admin//desktop//data") #设置路径
iris=read.table ("Iris.txt") 
names (Iris) =c ("v1", "V2", "V3" , "V4", "label") #设置变量名
var=iris$label #将标签赋予var
Var=as.character (Var)  #将var转换为字符型

Two k-medoids cluster
The K-Center point algorithm and the K-means algorithm are very close to the principle, the main difference is that when the center point of each category is selected, the K-Center point algorithm is selected within the category to the remaining sample distance and the smallest sample as the center.
The K-center point algorithm in R packages for cluster is the main function of Pam ().

Install.packages ("cluster")
library (cluster)

kc=pam (iris[,-5],3)  #去掉标签
Print (KC)
Kc=pam ( iris[,-1],3,cluster.only=true) #显示聚类结果
print (KC)


Medoids: This item indicates which sample points are the various types of clusters completed when clustering is completed, and how many of their variables are evaluated.
Objective function: This item gives the value of the target equation in the two process of build and swap. The build process is used to find the optimal initial center point without specifying the initial center point, while the swap process is used to find the local optimal classification state for the target equation based on the initial center point.

Three EM Clustering

Library (Mclust)
fit_em=mclust (iris[,-5])
Summary (fit_em)
fit_em=mclustbic (iris[,-5]) # a second cluster function
bicsum=summary (fit_em,data=iris[,-5])


There is a visualization of clustering results, but for high-dimensional data, it is intended to be studied again.

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.