O'Reilly logo

R for Data Science by Dan Toomey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

K-means clustering

K-means is the process of assigning objects to groups so that the sum of the squares of the groups is minimized. R has the kmeans function available for cluster analysis. K-means is a method of determining clusters based on partitioning the data and assigning items in the dataset to the nearest cluster.

K-means clustering is done in R using the kmeans function. The kmeans function is defined as follows:

kmeans(x, centers, iter.max = 10, nstart = 1,
   algorithm = c("Hartigan-Wong", "Lloyd", "Forgy","MacQueen"), trace=FALSE)

The various parameters of this function are described in the following table:

Parameter

Description

x

This is the dataset.

centers

This contains the number of centers/clusters to find.

iter.max

This ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required