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.