← 返回 waymo 的题目列表K-means Clustering Implementation
类型:online_judge
Implement a K-means clustering algorithm.
Input: An integer k (number of clusters), a 2D list points (each element represents a coordinate point).
Output: A 2D list containing k clusters, with each element corresponding to a data point within the cluster.
Provide two methods for initial cluster centers: random selection and K-means++ initialization.
The input data size is: 1 <= len(points), len(points[i]) <= 1000.
Example:
Input: k = 2, points = [[1, 2], [1, 4], [3, 4], [5, 2], [5, 6]]
Output: [[[1, 2], [1, 4], [3, 4]], [[5, 2], [5, 6]]]
Example
Input
2 [[1, 2], [1, 4], [3, 4], [5, 2], [5, 6]]