ML-Unit III - K-Means Clustering
ML-Unit III - K-Means Clustering
A1(2, 10), A2(2, 5), A3(8, 4), A4(5, 8), A5(7, 5), A6(6, 4), A7(1, 2), A8(4, 9)
Initial cluster centers are: C1(2, 10), C2(5, 8) and C3(1, 2).
We calculate the distance of each point from each of the center of the three clusters.
Calculating Distance Between A1(2, 10) and C1(2, 10): Ρ(A1, C1) = |x2 – x1| + |y2 – y1| = |2 – 2| + |10 – 10| = 0
Calculating Distance Between A1(2, 10) and C2(5, 8): Ρ(A1, C2) = |x2 – x1| + |y2 – y1| = |5 – 2| + |8 – 10| = 3 + 2 = 5
Calculating Distance Between A1(2, 10) and C3(1, 2): Ρ(A1, C3) = |x2 – x1| + |y2 – y1| = |1 – 2| + |2 – 10| = 1 + 8 = 9
According to this, Distance Between A1(2, 10) and C1(2, 10) is minimum and it will go in cluster C1.
In the similar manner, we calculate the distance of other points from each of the center of the three clusters.
K-means clustering: Exercise
Solution: Iteration 1
K-means clustering: Exercise
Solution: Iteration 1
Cluster-01:
Cluster-02:
Cluster-03:
Cluster-01:
Center = C1(2,10)
Cluster-02:
Center=C2(6,6)
Cluster-03:
Center = C3(1.5,3.5)
K-means clustering: Exercise
Solution: Iteration 2
Cluster-01:
Cluster-02:
For Cluster-02: A3(8, 4) A4(5, 8) A5(7, 5) A6(6, 4) C1(3, 9.5) C2(6.5, 5.25) C3(1.5, 3.5)
Center of Cluster-02 = ((8 + 5 + 7 + 6)/4, (4 + 8 + 5 + 4)/4) =
(6.5, 5.25)
Initialize centroids
Assign Cluster
Move Centroids
Finish
K-means Clustering: Elbow method
● How to decides number of clusters?
○ The elbow method is a graphical representation of finding the optimal
‘K’ in a K-means clustering.
○ It works by finding WCSS (Within-Cluster Sum of Square) i.e. the sum
of the square distance between points in a cluster and the cluster
centroid.
K-means Clustering: Elbow method