, k- . , , . k- (centroid), . , . . , , , . 1:
[a] (61.0, 100.0)
[b] (64.0, 150.0)
[c] (70.0, 140.0)
? , . :
[m] = ((61.0 + 64.0 + 70.0) / 3, (100.0 + 150.0 + 140.0) / 3)
= (195.0 / 3, 390.0 / 3)
= (65.0, 130.0)
, (65.0, 130.0)? . , , , (Euclidean distance). , . . (61.0, 100.0) (65.0, 130.0) :
dist(m,a) = sqrt((65.0 - 61.0)^2 + (130.0 - 100.0)^2)
= sqrt(4.0^2 + 30.0^2)
= sqrt(16.0 + 900.0)
= sqrt(916.0)
= 30.27
:
dist(m,b) = sqrt((65.0 - 64.0)^2 + (130.0 - 150.0)^2)
= 20.02
dist(m,c) = sqrt((65.0 - 70.0)^2 + (130.0 - 140.0)^2)
= 11.18
[c], [c]. , , , , .
, k-. :
loop maxCount
( )
( )
end loop
return
, k- . . 2 , . , , .
. 2.
Weight (pounds) | ( ) |
Cluster 0 | 0 |
Cluster 1 | 1 |
Cluster 2 | 2 |
Height (inches) | ( ) |