Given k and k manually selected initial clusters, run K-Means and display each iteration.
Input:
python3 Kmeans-driver.py --table_csv table.csv
Enter 3 points with 2, each separated by a single comma:
0-> 2,10
1-> 5,8
2-> 1,2
Output:
Note: the output format is (point) -> distance(point, c1) | ... | Cluster that this point belongs to BEFORE the iteration. That's why in the 1st iteration, all points' cluster are still 0.
Iteration 1
C0: (2, 10)
C1: (5, 8)
C2: (1, 2)
(2, 10) -> 0.0 | 3.605551275463989 | 8.06225774829855 | Cluster 0
(2, 5) -> 5.0 | 4.242640687119285 | 3.1622776601683795 | Cluster 0
(8, 4) -> 8.48528137423857 | 5.0 | 7.280109889280518 | Cluster 0
(5, 8) -> 3.605551275463989 | 0.0 | 7.211102550927978 | Cluster 0
(7, 5) -> 7.0710678118654755 | 3.605551275463989 | 6.708203932499369 | Cluster 0
(6, 4) -> 7.211102550927978 | 4.123105625617661 | 5.385164807134504 | Cluster 0
(1, 2) -> 8.06225774829855 | 7.211102550927978 | 0.0 | Cluster 0
(4, 9) -> 2.23606797749979 | 1.4142135623730951 | 7.615773105863909 | Cluster 0
Iteration 2
C0: (2.0, 10.0)
C1: (6.0, 6.0)
C2: (1.5, 3.5)
(2, 10) -> 0.0 | 5.656854249492381 | 6.519202405202649 | Cluster 0
(2, 5) -> 5.0 | 4.123105625617661 | 1.5811388300841898 | Cluster 2
(8, 4) -> 8.48528137423857 | 2.8284271247461903 | 6.519202405202649 | Cluster 1
(5, 8) -> 3.605551275463989 | 2.23606797749979 | 5.70087712549569 | Cluster 1
(7, 5) -> 7.0710678118654755 | 1.4142135623730951 | 5.70087712549569 | Cluster 1
(6, 4) -> 7.211102550927978 | 2.0 | 4.527692569068709 | Cluster 1
(1, 2) -> 8.06225774829855 | 6.4031242374328485 | 1.5811388300841898 | Cluster 2
(4, 9) -> 2.23606797749979 | 3.605551275463989 | 6.041522986797286 | Cluster 1
Iteration 3
C0: (3.0, 9.5)
C1: (6.5, 5.25)
C2: (1.5, 3.5)
(2, 10) -> 1.118033988749895 | 6.5431261641512 | 6.519202405202649 | Cluster 0
(2, 5) -> 4.6097722286464435 | 4.5069390943299865 | 1.5811388300841898 | Cluster 2
(8, 4) -> 7.433034373659253 | 1.9525624189766635 | 6.519202405202649 | Cluster 1
(5, 8) -> 2.5 | 3.132491021535417 | 5.70087712549569 | Cluster 1
(7, 5) -> 6.020797289396148 | 0.5590169943749475 | 5.70087712549569 | Cluster 1
(6, 4) -> 6.264982043070834 | 1.346291201783626 | 4.527692569068709 | Cluster 1
(1, 2) -> 7.762087348130012 | 6.388466169590319 | 1.5811388300841898 | Cluster 2
(4, 9) -> 1.118033988749895 | 4.5069390943299865 | 6.041522986797286 | Cluster 0
Iteration 4
C0: (3.6666666666666665, 9.0)
C1: (7.0, 4.333333333333333)
C2: (1.5, 3.5)
(2, 10) -> 1.9436506316151 | 7.557189365836423 | 6.519202405202649 | Cluster 0
(2, 5) -> 4.333333333333333 | 5.044248650140519 | 1.5811388300841898 | Cluster 2
(8, 4) -> 6.61647774709307 | 1.0540925533894596 | 6.519202405202649 | Cluster 1
(5, 8) -> 1.6666666666666667 | 4.176654695380556 | 5.70087712549569 | Cluster 0
(7, 5) -> 5.2068331172711035 | 0.666666666666667 | 5.70087712549569 | Cluster 1
(6, 4) -> 5.517648452415616 | 1.0540925533894596 | 4.527692569068709 | Cluster 1
(1, 2) -> 7.490735018081411 | 6.437735971942655 | 1.5811388300841898 | Cluster 2
(4, 9) -> 0.3333333333333335 | 5.547772325697746 | 6.041522986797286 | Cluster 0
Iteration 5
C0: (3.6666666666666665, 9.0)
C1: (7.0, 4.333333333333333)
C2: (1.5, 3.5)
(2, 10) -> 1.9436506316151 | 7.557189365836423 | 6.519202405202649 | Cluster 0
(2, 5) -> 4.333333333333333 | 5.044248650140519 | 1.5811388300841898 | Cluster 2
(8, 4) -> 6.61647774709307 | 1.0540925533894596 | 6.519202405202649 | Cluster 1
(5, 8) -> 1.6666666666666667 | 4.176654695380556 | 5.70087712549569 | Cluster 0
(7, 5) -> 5.2068331172711035 | 0.666666666666667 | 5.70087712549569 | Cluster 1
(6, 4) -> 5.517648452415616 | 1.0540925533894596 | 4.527692569068709 | Cluster 1
(1, 2) -> 7.490735018081411 | 6.437735971942655 | 1.5811388300841898 | Cluster 2
(4, 9) -> 0.3333333333333335 | 5.547772325697746 | 6.041522986797286 | Cluster 0