| KMEANS | R Documentation |
Run K-means for clustering.
KMEANS(
d,
k = 9,
criterion = c("none", "pseudo-F", "silhouette", "gap", "elbow"),
nstart = 10,
B = 100,
graph = FALSE,
seed = NULL,
...
)
d |
The dataset ( |
k |
The number of cluster. |
criterion |
How the number of clusters is chosen: |
nstart |
Define how many random sets should be chosen. |
B |
The number of bootstrap samples used by |
graph |
A logical indicating whether or not a graphic should be plotted (cluster number selection). |
seed |
A specified seed for random number generation. K-means starts from a random initialisation, so without a seed two calls on the same data give different clusterings; every other clustering function of the package already had this parameter. |
... |
Other parameters. |
The four criteria criterion offers, all computed between 2 clusters and k:
"pseudo-F"the Calinski-Harabasz index, between-cluster over within-cluster variance corrected for the number of clusters. Maximised.
"silhouette"the mean silhouette width – how much closer each observation is to its own cluster than to the nearest other one. Maximised.
"gap"the gap statistic: the distance between the observed within-cluster
dispersion and the one expected with no cluster structure at all. The retained k
is the smallest whose gap is within one standard error of the next. It is the only
criterion that can answer k = 1, and much the slowest, needing B
bootstrap samples.
"elbow"the bend of the total within-cluster sum of squares. That quantity
decreases with k whatever the data, so there is no optimum to take: the retained
k is the point furthest from the chord joining the two ends of the curve, drawn
on the graphic.
The last three need the cluster package.
The clustering (kmeans object).
kmeans, predict.kmeans
require (datasets)
data (iris)
KMEANS (iris [, -5], k = 3)
KMEANS (iris [, -5], criterion = "pseudo-F") # With automatic detection of the nmber of clusters
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.