What Is K-Means?
K-Means is a clustering algorithm that divides data into a chosen number of groups based on how similar the data points are.
K-Means finds similar data points and puts them into groups.
You tell K-Means how many groups you want by choosing a value for K. K-Means then tries to organize the data into those groups.
What Does K-Means Mean?
The name K-Means contains two important ideas: K and Means.
K tells the algorithm how many groups we want to create.
K-Means uses the average position of the points in a cluster to find its center.
What Does K Control?
The value of K determines how many groups K-Means should create.
● ●
● ●
So when you write:
KMeans(n_clusters=3)
you are telling the algorithm:
Simple Customer Example
Imagine an online store has customers with different spending habits.
We record two features:
How much money the customer spends.
How many purchases the customer makes.
Looking at the numbers, customers A, B, and E are relatively similar.
Customers C and D are also relatively similar.
K-Means Can Find These Groups
Suppose we choose:
We are asking K-Means to create two groups.
These customers have relatively lower spending and fewer purchases.
These customers have much higher spending and more purchases.
What Is the "Mean"?
The word Means comes from the idea of calculating the average position of the points in a cluster.
For example, imagine three values:
The mean is 20.
K-Means uses this idea to find the center of each cluster. This center is called a centroid.
K-Means Is Unsupervised Learning
From the previous page, you learned that unsupervised learning works without predefined labels.
K-Means is an example of unsupervised learning because we don't tell it which customer belongs to which group.
Example: spending and number of purchases.
Similar customers are placed into clusters.
What K-Means Does Not Tell You
There is an important detail beginners often misunderstand.
If K-Means produces:
Cluster 0 Cluster 1
that does not automatically mean:
Cluster 0 = Low-value customers Cluster 1 = High-value customers
The numbers are simply identifiers.
After clustering, we inspect the data inside each cluster and decide what the groups actually represent.
One More Simple Example
Imagine a school has information about students' study hours and attendance, but no student categories.
If we choose:
K-Means might discover:
Students with lower study hours and attendance.
Students with higher study hours and attendance.
K-Means = Choose K + Find Similar Groups
K-Means is an unsupervised clustering algorithm. You choose how many clusters you want using K, and the algorithm organizes similar data points into those clusters.