After assigning each point to a cluster, the centroid update step recomputes each centroid as the mean of all points assigned to it. This is the second half of one K-Means iteration.
Given a list of data points, their cluster assignments, and the number of clusters k, compute the new centroid positions.
For each cluster j, the new centroid is the mean of all assigned points:
cj=∣Sj∣1p∈Sj∑pWhere S_j is the set of points assigned to cluster j.
Return k centroids as a list of lists of floats.
Input: points = [[0, 0], [2, 2], [10, 10], [12, 12]], assignments = [0, 0, 1, 1], k = 2
Output: [[1.0, 1.0], [11.0, 11.0]]
Explanation: Each centroid is the coordinate-wise mean of the points assigned to its cluster.
Input: points = [[0, 0], [1, 0], [5, 5], [6, 5], [10, 0]], assignments = [0, 0, 1, 1, 2], k = 3
Output: [[0.5, 0.0], [5.5, 5.0], [10.0, 0.0]]
Accumulate a coordinate sum and point count for each cluster.
Divide each coordinate sum by its cluster count, using a zero vector for an empty cluster.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
After assigning each point to a cluster, the centroid update step recomputes each centroid as the mean of all points assigned to it. This is the second half of one K-Means iteration.
Given a list of data points, their cluster assignments, and the number of clusters k, compute the new centroid positions.
For each cluster j, the new centroid is the mean of all assigned points:
cj=∣Sj∣1p∈Sj∑pWhere S_j is the set of points assigned to cluster j.
Return k centroids as a list of lists of floats.
Input: points = [[0, 0], [2, 2], [10, 10], [12, 12]], assignments = [0, 0, 1, 1], k = 2
Output: [[1.0, 1.0], [11.0, 11.0]]
Explanation: Each centroid is the coordinate-wise mean of the points assigned to its cluster.
Input: points = [[0, 0], [1, 0], [5, 5], [6, 5], [10, 0]], assignments = [0, 0, 1, 1, 2], k = 3
Output: [[0.5, 0.0], [5.5, 5.0], [10.0, 0.0]]
Accumulate a coordinate sum and point count for each cluster.
Divide each coordinate sum by its cluster count, using a zero vector for an empty cluster.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number