spark Bisecting k-means(二分K均值算法)


Bisecting k-means(二分K均值算法)

       二分k均值(bisecting k-means)是一種層次聚類方法,算法的主要思想是:首先將所有點作為一個簇,然后將該簇一分為二。之后選擇能最大程度降低聚類代價函數(也就是誤差平方和)的簇划分為兩個簇。以此進行下去,直到簇的數目等於用戶給定的數目K為止。 
       以上隱含着一個原則是:因為聚類的誤差平方和能夠衡量聚類性能,該值越小表示數據點月接近於它們的質心,聚類效果就越好。所以我們就需要對誤差平方和最大的簇進行再一次的划分,因為誤差平方和越大,表示該簇聚類越不好,越有可能是多個簇被當成一個簇了,所以我們首先需要對這個簇進行划分。

       bisecting k-means通常比常規K-Means方法運算快一些,也和K-Means聚類方法得到結果有所不同。 
    Bisecting k-means is a kind of hierarchical clustering using a divisive (or “top-down”) approach: all observations start in one cluster, and splits are performed recursively as one moves down the hierarchy. 
    Bisecting K-means can often be much faster than regular K-means, but it will generally produce a different clustering. 
       二分k均值算法的偽代碼如下:

將所有的點看成一個簇 當簇數目小於k時 對每一個簇: 計算總誤差 在給定的簇上面進行k-均值聚類k=2 計算將該簇一分為二后的總誤差 選擇使得誤差最小的那個簇進行划分操作
//BisectingKMeans和K-Means API基本上是一樣的,參數也是相同的 //模型訓練 val bkmeans=new BisectingKMeans() .setK(2) .setMaxIter(100) .setSeed(1L) val model=bkmeans.fit(dataset) //顯示聚類中心 model.clusterCenters.foreach(println) //SSE(sum of squared error)結果評估 val WSSSE=model.computeCost(dataset) println(s"within set sum of squared error = $WSSSE")

Bisecting k-means優缺點 
       同k-means算法一樣,Bisecting k-means算法不適用於非球形簇的聚類,而且不同尺寸和密度的類型的簇,也不太適合。

 

摘自:http://blog.csdn.net/qq_34531825/article/details/52663428


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM