Recently, we want to build a clustering project on spark, with a large amount of data and classes. The kmeans effect is acceptable, but it is a little slow, so I re-read the common algorithms.
Kmeans
Attention: init Centers (randomize vs kmeans ++)
Mini-Batch kmeans
Loops: random samples; find closest for all; update centers for each
Mean Shift
Init: Get centers by bandwidth
Loops: Find neighbors of centers; update centers; dedup
AP Cluster
Init: Get S; Rik = 0, AIK = 0
Loops: Rik = Sik-max_k '! = K (AIK '+ Sik'); AIK = min (0, rkk + sum_ I '! = I, K max (0, RI 'K); Akk = sum_ I '! = K max (0, RI 'K)
End: For any I, max_k rik + AIK as it's exemplar
Spectral clustering
Steps: similarity Matrix s; S = uv; kmeans of u
Ward hierarchical
Init: each sample as center
Loops: merge to minimize RMSE within clusters
DBSCAN
Init: Get densest core samples
Loops: get more core samples nearby old samples
In fact, scikit-learn implements many algorithms, and there are also ready-made datasets that can be used for experiments. For example: there are some http://scikit-learn.org/stable/modules/clustering.html, and algorithm expansion description.
A comparison of the clustering algorithms in scikit-learn
| Method Name |
Parameters |
Scalability |
Usecase |
Geometry (metric used) |
| K-means |
Number of clusters |
Very largeN_samples, MediumN_clustersWithMinibatch code |
General-purpose, even cluster size, flat geometry, not too many ters |
Distances between points |
| Affinity propagation |
Damping, sample preference |
Not scalable with n_samples |
Many clusters, uneven cluster size, non-flat Geometry |
Graph distance (e.g. nearest-neighbor graph) |
| Mean-shift |
Bandwidth |
Not scalableN_samples |
Many clusters, uneven cluster size, non-flat Geometry |
Distances between points |
| Spectral clustering |
Number of clusters |
MediumN_samples, SmallN_clusters |
Few clusters, even cluster size, non-flat Geometry |
Graph distance (e.g. nearest-neighbor graph) |
| Ward hierarchical clustering |
Number of clusters |
LargeN_samplesAndN_clusters |
Many clusters, possibly connectivity constraints |
Distances between points |
| Agglomerative Clustering |
Number of clusters, linkage type, distance |
LargeN_samplesAndN_clusters |
Many clusters, possibly connectivity constraints, Non Euclidean distances |
Any pairwise distance |
| DBSCAN |
Neighborhood Size |
Very largeN_samples, MediumN_clusters |
Non-flat geometry, uneven cluster sizes |
Distances between nearest points |
| Gaussian mixtures |
Bytes |
Not scalable |
Flat geometry, good for Density Estimation |
Mahalanobis distances to centers |
Clustering Algorithm Summary