{% extends "base.html" %} {% block title %} kmeans {% endblock %} {% block description %}

Finds centers of clusters and groups input samples around the clusters.

{% endblock %} {% block signature %}
cv2.kmeans(data, K, bestLabels, criteria, attempts, flags[, centers]) → retval, bestLabels, centers
{% endblock %} {% block parameters %} {% endblock %} {% block explanation %}

The function kmeans implements a k-means algorithm that finds the centers of K clusters and groups the input samples around the clusters. As an output, bestLabels[i] contains a 0-based cluster index for the sample stored in the \(i^{th}\) row of the samples matrix.

The function returns retVal, the compactness measure that is computed as $$\sum_i \| \text{samples}_i - \text{centers}_{\text{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.

{% endblock %} {% block notes %}

{% endblock %} {% block references %} {% endblock %}