cv.kmeans - MATLAB File Help
cv.kmeans

Finds centers of clusters and groups input samples around the clusters

labels = cv.kmeans(data, K)
[labels, centers, compactness] = cv.kmeans(...)
[...] = cv.kmeans(..., 'OptionName', optionValue, ...)

Input

Output

Options

The function cv.kmeans implements a k-means algorithm that finds the centers of K clusters and groups the input samples around the clusters. As an output, 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} (|| samples_i - centers_{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 InitialLabels option, and then choose the best (most-compact) clustering.

References

[Arthur2007]:

D. Arthur, S. Vassilvitskii: "k-means++: The Advantages of Careful Seeding". In Proceedings of the eighteenth annual ACM-SIAM symposium on Discrete algorithms, 1027-1035, 2007.

See also