O'Reilly logo

Python Data Structures and Algorithms by Benjamin Baka

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 algorithm

The k-means algorithm uses the mean points in a given dataset to cluster and discover groups within the dataset. K is the number of clusters that we want and are hoping to discover. After the k-means algorithm has generated the groupings, we can pass it additional but unknown data for it to predict to which group it will belong.

Note that in this kind of algorithm, only the raw uncategorized data is fed to the algorithm. It is up to the algorithm to find out if the data has inherent groups within it.

To understand how this algorithm works, we will examine 100 data points consisting of x and y values. We will feed these values to the learning algorithm and expect that the algorithm will cluster the data into two sets. We ...

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