What is k-means, How to set K?

What is K-means?

figure cited here, recommend reading: K-Means Clustering – What it is and How it Works

K-means is a clustering algorithm, so it's one of the unsupervised machine learning algorithms.

This algorithm aims to group the data into K clusters.

Firstly, we predefine a K, and choose K data points arbitrarily as the centers of K clusters.

Secondly, for each data, we calculate its distances with the K centers.
Select its nearest center and distribute it to this cluster.

Thirdly, after distributing all the data points, we compute the new centers within each cluster.

Then iterate step 2 and 3 until the centers are no longer change.

In a word, K-means is to get K clusters, use means to calculate the centers, and assign each sample to its nearest center.


How to set K?

Start with k equals to 1, and calculate its variation which is the worst.
Then try k equals to 2, and compare its variation with k=1.
...
Each time we increase k, the total variation is smaller than before.
Let's plot the reduction in variance per value for k, and find the largest reduction point, like an elbow.
For example, this figure shows that when k=3, the variation has the hugest reduction, so we can set k equals to 3.

figure cited here, recommend reading: StatQuest: K-means clustering

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章