K-Means is a partition-based Clustering algorithm that assigns points to the nearest of centroids and updates centroids to the mean of their members.
Algorithm
- choose the number of clusters k
- Init k centroids randomly
- Repeat until convergence:
- assign each data point to the nearest centroid
- update each centroid to the mean of the assigned data points
- distance metrics: typically use Euclidean Distance, but can use others like Manhattan Distance. It really depends on the data and task
Cons & Pros
Initialization of the centroids will affects the clustering results
Convergence
K-mean always converges but can’t guarantee the global optimum
Time complexity: :
is # of points
is # of clusters
is # of interations
Explain to Others
given point, 1, 2, 4, implement algorithm, given k = 2 :
- select 1, 2 as centroids
- calculate distance(distance metrics) between each point with centroid points
- 1,1
- 1,2
- 1,4
References
- Visualizing K-Means Clustering
- can study more with codes from Visualizing Clustering Algorithms: K-Means and DBSCAN