一、k-均值算法
點分配聚類算法中最著名的一個稱爲k-均值算法。該算法假設在歐式空間下,並假設最終簇的數目k事先已知。
3.1 k-均值算法的基礎
代表簇的k個初始點選擇有多種方法。在算法的核心for循環中,我們將k個初始點之外的每個點就近分配給最近(離簇的質心最近)的簇。需要注意的是當新的點分配到一個簇之後,質心可能會漂移。但是由於只有簇附近的點纔可能會被分配給自己,所以簇的質心也不會移動太大。算法描述如下:
Initially choose k points that are likely to be in different clusters;
Make these points the centroids of their clusters;
For each remaining point p DO:
Find the centroid to which p is closest;
Add p to the cluster of that centroid;
Adjust the centroid of that cluster to account for p;
END;
算法的一個變形是固定所有簇的質心,然後將包含k個初始點的所有點重新分配到這k個簇中。
k-均值選擇K的個數依靠可視化數據和實際的需要手工決定K,隨機選擇μ1,,...μk即初始的K個簇心centeroid。
如何優化隨機化選擇K個簇心:
1:如果K∈(2,10),運行100次左右的隨機化過程,然後計算每一次運行的cost函數:也叫Distortion Function.
min J(C1,...Cm, μ1,...μk) = 1/m* sum(||xi - μci||^2)
For each remaining point p DO: (x1到xm)
Find the centroid to which p is closest; (cp = k)
Add p to the cluster of that centroid; (add xp)
ADD STEP TO GET J: ||xp - μk||^2
Adjust the centroid of that cluster to account for p; (調整uk)
END;
J = 1/m* sum();
2: 如果k特別的多,進行多次隨機化過程沒有太多的用處。