|
clusters = [Cluster(centroid.record) for centroid in rdd.takeSample(False, n_partitions * n_clusters, seed=None)] |
On the line 253, modes are initialised by randomly selecting records from the whole rdd (and not from the corresponding partition).
As a result, on line 96, the random modes initialised from the whole dataset are used instead of modes for the particular partition.
In most cases, this results in undefined behaviour of the algorithm, i.e. in attempt to use records from one partition with the mode from another partition. In turn, this leads to empty clusters (which should never happen in the incremental k-means/k-modes, please see https://stackoverflow.com/questions/43445863/k-meansupdaing-centroids-successively-after-each-addition for details). In the code, it is solved with the function "check_for_empty_cluster(clusters, rdd)" which replaces the mode of emty cluster with a random one in the middle of k-modes execution.
All in all, this leads to the wrong results of the clustering.
pyspark-distributed-kmodes/pyspark_kmodes/pyspark_kmodes.py
Line 253 in 98b27d7
On the line 253, modes are initialised by randomly selecting records from the whole rdd (and not from the corresponding partition).
As a result, on line 96, the random modes initialised from the whole dataset are used instead of modes for the particular partition.
In most cases, this results in undefined behaviour of the algorithm, i.e. in attempt to use records from one partition with the mode from another partition. In turn, this leads to empty clusters (which should never happen in the incremental k-means/k-modes, please see https://stackoverflow.com/questions/43445863/k-meansupdaing-centroids-successively-after-each-addition for details). In the code, it is solved with the function "check_for_empty_cluster(clusters, rdd)" which replaces the mode of emty cluster with a random one in the middle of k-modes execution.
All in all, this leads to the wrong results of the clustering.