K-medodis and K-means are similar, but K-medoids and K-means are different, the difference lies in the selection of the center point, in K-means, we will take the center point as the average of all data points in the current cluster, in In the K-medoids algorithm, we will select such a point from the current cluster-its minimum distance from all other points in the current cluster-as the center point. The K-medodis algorithm is not susceptible to dirty data due to errors and the like, but the computational amount is obviously larger than the K-means, which is generally only suitable for small data volumes . K-medoids mainly applies to the PAM function in the cluster packet in the R language.
K Center Point Clustering
cluster::p am
Usage: Pam (x, K, diss = Inherits (x, "dist"), metric = "Euclidean", Medoids = NULL, stand = FALSE, cluster.only = FALSE, Do.swap = TRUE, Keep.diss =!diss &&!cluster.only && n <, Keep.data =!diss &&A MP;!cluster.only, pamonce = FALSE, Trace.lev = 0)
- X: Cluster Object
- K: is the number of clusters ( positive integer specifying the numbers of the clusters, less than the NUM of observations)
Sample code
> Newiris <-iris[,-5]> Library (Cluster)> KC <-pam (x=newiris,k=3)# kc$clustering#Kc[1:length (KC)]> > table (iris$species, kc$clustering) 1 2 3 setosa 0 0 versicolor 48 2 virginica 14 36
Summary:
An improved algorithm for the disadvantage of K-means is susceptible to extreme value. The difference in principle is that the sample mean point is not taken when the center point of a class is selected, and the sample that is selected to the remaining sample distance within the category is centered.
FPC::p AMK
Compared to the PAM function, the number of reference clusters can be given, referring to Kmenas and Kmeansrun
USAGE:PAMK (data,krange=2:10,criterion= "ASW", Usepam=true, Scaling=false, alpha=0.001, diss=inherits (data, "dist"), Critout=false, ns=10, Seed=null, ...)
Sample code
Newiris <-<-<-pamk (newiris,krang=1:5) plot (Pam (Newiris, KC2$NC))
legend
The FPC package also provides another function plotcluster () that shows the clustering analysis, and it is worth mentioning that the data will be projected into different clusters
Plotcluster (Newiris,kc2$cluster)
Pending verification:
Why are there only two clusters?
References:
- http://blog.csdn.net/helen1313/article/details/38111125
ML: Clustering Algorithm R Package-K Center Point clustering