K-Means 聚类实例sample
假定我們有如下9個點
A1(2, 10) ?A2(2, 5)?A3(8, 4) ?A4(5, 8) ?A5(7, 5)?A6(6, 4)? A7(1, 2)? A8(4, 9)
希望分成3個聚類
初始化選擇?A1(2, 10),? A4(5, 8) ,A7(1, 2)為聚類中心點,兩點距離定義為ρ(a, b) = |x2 – x1| + |y2 – y1|?. ?
第一步
Iteration 1
| ? | ? | ???????? (2, 10) | ??????? (5, 8) | ???????? (1, 2) | ? |
| ? | Point | Dist Mean cluster 1 | Dist Mean?cluster2 | Dist Mean?cluster?3 | Cluster |
| A1 | (2, 10) | ? | ? | ? | ? |
| A2 | (2, 5) | ? | ? | ? | ? |
| A3 | (8, 4) | ? | ? | ? | ? |
| A4 | (5, 8) | ? | ? | ? | ? |
| A5 | (7, 5) | ? | ? | ? | ? |
| A6 | (6, 4) | ? | ? | ? | ? |
| A7 | (1, 2) | ? | ? | ? | ? |
| A8 | (4, 9) | ? | ? | ? | ? |
對A1點,計算其到每個cluster?的距離
A1->class1 = |2-2|+|10-10}=0
A1->class2 = |2-5|+|10-8|=5
A1->class3 = |2-1|+|10-2|=9
因此A1 屬于cluster1
| ? | ? | ???????? (2, 10) | ??????? (5, 8) | ???????? (1, 2) | ? |
| ? | Point | Dist Mean?cluster??1 | Dist Mean?cluster?2 | Dist Mean?cluster?3 | Cluster |
| A1 | (2, 10) | 0 | 5 | 9 | 1 |
| A2 | (2, 5) | ? | ? | ? | ? |
| A3 | (8, 4) | ? | ? | ? | ? |
| A4 | (5, 8) | ? | ? | ? | ? |
| A5 | (7, 5) | ? | ? | ? | ? |
| A6 | (6, 4) | ? | ? | ? | ? |
| A7 | (1, 2) | ? | ? | ? | ? |
| A8 | (4, 9) | ? | ? | ? | ? |
余下繼續計算,直到
| ? | ? | ???????? (2, 10) | ??????? (5, 8) | ???????? (1, 2) | ? |
| ? | Point | Dist Mean?cluster?1 | Dist Mean?cluster?2 | Dist Mean?cluster?3 | Cluster |
| A1 | (2, 10) | 0 | 5 | 9 | 1 |
| A2 | (2, 5) | 5 | 6 | 4 | 3 |
| A3 | (8, 4) | 12 | 7 | 9 | 2 |
| A4 | (5, 8) | 5 | 0 | 10 | 2 |
| A5 | (7, 5) | 10 | 5 | 9 | 2 |
| A6 | (6, 4) | 10 | 5 | 7 | 2 |
| A7 | (1, 2) | 9 | 10 | 0 | 3 |
| A8 | (4, 9) | 3 | 2 | 10 | 2 |
重新計算中心點
cluster1只有1個點,因此A1為中心點
cluster2的中心點為?( (8+5+7+6+4)/5,(4+8+5+4+9)/5 )=(6,6)。注意:這個點并不實際存在。
cluster3的中心點為( (2+1)/2, (5+2)/2 )= (1.5, 3.5)
圖形化的過程如下:
持續迭代,直到前后兩次迭代不發生變化為止,如下:
以上例子來源:http://www.google.com/url?sa=t&rct=j&q=&esrc=s&frm=1&source=web&cd=1&ved=0CDsQFjAA&url=http%3A%2F%2Ffaculty.uscupstate.edu%2Fatzacheva%2FSHIM450%2FKMeansExample.doc&ei=ZDMVT56XJOmoiQLeyLm9DQ&usg=AFQjCNHMUw4sLHM82Pu6cXc2DTSz-cz2pw
from:?http://blog.csdn.net/pennyliang/article/details/7207466
總結
以上是生活随笔為你收集整理的K-Means 聚类实例sample的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Machine Learning实验5
- 下一篇: 关于编译器的一个问题