Clustering
kmeans
Finds centers of clusters and groups input samples around the clusters.
The function kmeans
implements a k-means algorithm that finds the
centers of cluster_count
clusters and groups the input samples
around the clusters. As an output,
\texttt{labels}_i
contains a 0-based cluster index for
the sample stored in the
i^{th}
row of the samples
matrix.
The function returns the compactness measure that is computed as
\sum _i \| \texttt{samples} _i - \texttt{centers} _{ \texttt{labels} _i} \| ^2
after every attempt. The best (minimum) value is chosen and the
corresponding labels and the compactness value are returned by the function.
Basically, you can use only the core of the function, set the number of
attempts to 1, initialize labels each time using a custom algorithm, pass them with the
( flags
= KMEANS_USE_INITIAL_LABELS
) flag, and then choose the best (most-compact) clustering.
Note
- An example on K-means clustering can be found at opencv_source_code/samples/cpp/kmeans.cpp
- (Python) An example on K-means clustering can be found at opencv_source_code/samples/python2/kmeans.py
partition
Splits an element set into equivalency classes.
The generic function partition
implements an
O(N^2)
algorithm for
splitting a set of
N
elements into one or more equivalency classes, as described in
http://en.wikipedia.org/wiki/Disjoint-set_data_structure
. The function
returns the number of equivalency classes.
[Arthur2007] | Arthur and S. Vassilvitskii. k-means++: the advantages of careful seeding, Proceedings of the eighteenth annual ACM-SIAM symposium on Discrete algorithms, 2007 |