Friday, 24 January 2014

k-means clustering calculator

This blog post implements a basic k-means clustering algorithm, which can be applied to either a scalar number or 2-d data (x and y component). Graphs of the clustered data and algorithm convergence (as measured by the changes in cluster membership of the data samples between consecutive iterations) are displayed below.

The cluster centres (or centroids) are initialised using the k-means++ algorithm as proposed by David Arthur and Sergei Vassilvitski in 2007.

Please enter the numbers in the text areas below - either one number per line or two comma separated numbers per line. There must be no new line after the last number.

Alternatively you can choose to load a CSV file, which must be either a single column of numbers (for a real only input) or two comma-separated columns of numbers - the first line can be a comment line, starting with the character #.

To perform the k-means clustering, please enter the number of clusters and the number of iterations in the appropriate fields, then press the button labelled "Perform k-means clustering" below - the results will populate the textareas below labelled "Output" and "Centroid values". The "Output" textarea will list the sample values and the cluster/centroid index each sample belongs to, while the "Centroid values" textarea will list the centroid index and the value of the centroids (or cluster centres).

Note that the k-means algorithm can converge to a local minimum, and also exhibit degeneracy, whereby one of the clusters has no members. Should these scenarios occur, simply re-run the algorithm.



Input




Enter number of clusters (k value):-

Enter number of iterations:-





Output:-
Centroid values:-



Cluster Visualisation
Value
Samples
Algorithm convergence
Change
Iteration number

Summary statistics pending..

2 comments:

  1. US METRO POPULATIONS 2018 FROM WIKI
    19979477
    13291486
    9498716
    7539711
    6997384
    6249950
    6198782
    6096372
    5949951
    4875390
    4857962
    4729484
    4622361
    4326442
    3939363
    3629190
    3343364
    3142663
    2932415
    2805465
    2802789
    2572692
    2569213
    2518036
    2478810
    2345210
    2324743
    2231647
    2190209
    2168316
    2143651
    2106541
    2057009
    2048703
    1999107
    1930961
    1728733
    1621337
    1576113
    1534701
    1396445
    1362540
    1350620
    1306172
    1297310
    1270399
    1222540
    1206300
    1151801
    1130152
    1071082
    1069405
    1039073
    994400
    993797
    980080
    947866
    943823
    942198
    915927
    906626
    896764
    883309
    883169
    865939
    857620
    850967
    845553
    842913
    832666
    831310
    821573
    806548
    787643
    767711
    754610
    752660
    741104
    738939
    730426
    708009
    704845
    675669
    675067
    671456
    660422
    659605
    655409
    650502
    644888
    633768
    631761
    604167
    602871
    596849
    580166
    575412
    574659
    573493
    560793
    555485
    549815
    549128
    543557
    538952
    535420
    516697
    499942
    494883
    489364
    482040
    481893
    480891
    469764
    466978
    465861
    462693
    459585
    452950
    451679
    448273
    446610
    446527
    437631
    436341
    435594
    432102
    423908
    420152
    415247
    413757
    409979
    409526
    406892
    399148
    398655
    397261
    389494
    387094
    385145
    381451
    379611
    378488
    373225
    370963
    369811
    368416
    368373
    359977
    352823
    350518
    341298
    340318
    337658
    334590
    326078
    322424
    321591
    319068
    314672
    314305
    314172
    306616
    305451
    296224
    294436
    292264
    291410
    288212
    286419
    284010
    282318
    278799
    278644
    275910
    274765
    274255
    272295
    272061
    271942
    269805
    268049
    266784
    265947
    265653
    265429
    263353
    262431
    251446
    245471
    243575
    240219
    239643
    237524
    235232
    232594
    231993
    231256
    230221
    229737
    225685
    221828
    221083
    219802
    219564
    219417
    218022
    217686
    217522
    213413
    212128
    211306
    211037
    210080
    209550
    209136
    207636
    205560
    204961
    202719
    202148
    201451
    199801
    197683
    196584
    193835
    191996
    190800
    188597
    184998
    184029
    181827
    180040
    180005
    179914
    178902
    178599
    178550
    178337
    177432
    176805
    174848
    173588
    173401
    171700
    171677
    171451
    171020
    169725
    169659
    169507
    169405
    168669
    167762
    167529
    167295
    166436
    163941
    163129
    162805
    162124
    161505
    158823
    157672
    157413
    154835
    154141
    153378
    153207
    153044
    153009
    152046
    151520
    151366
    151306
    151096
    150972
    150972
    150242
    150056
    149414
    148904
    148749
    148245
    147929
    147149
    146174
    146021
    143983
    142854
    141314
    140794
    140259
    140045
    139810
    139417
    136808
    135428
    135277
    134585
    134487
    133991
    133777
    132678
    132532
    131730
    129209
    128754
    128206
    127335
    126770
    126490
    126348
    126198
    125462
    125219
    125043
    124475
    123625
    123248
    123007
    122492
    121436
    121099
    119943
    119711
    119114
    118791
    118581
    118456
    117272
    117064
    115456
    114772
    114277
    113664
    112664
    111755
    110096
    110024
    110007
    108987
    107679
    106512
    105424
    104712
    103923
    103066
    102811
    102793
    102663
    102501
    102299
    101647
    99619
    99154
    98976
    98971
    98105
    97980
    97927
    97915
    96982
    96854
    92560
    92101
    90033
    89515
    87393
    87138
    85088
    84254
    83696
    83209
    82753
    82366
    81643
    80495
    79115
    76806
    64981
    63018
    60913
    55414

    ReplyDelete