Implement robust k-means with k-means++ initialization
Company: Tencent
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates implementation and understanding of clustering algorithms (k-means with k-means++), vectorized numerical computing with NumPy, handling of edge cases such as empty clusters and sample weighting, and algorithmic complexity analysis in the Coding & Algorithms domain for Data Scientist roles.
Constraints
- X is a non-empty numeric matrix
- k may be larger than n and is capped at n
Examples
Input: ([[0, 0], [0, 2], [10, 10], [10, 12]], 2, 100, 0.0001, None, 0)
Expected Output: ([[0.0, 1.0], [10.0, 11.0]], [0, 0, 1, 1])
Explanation: Two separated 2D blobs.
Input: ([[1], [2], [10]], 5, 20, 0.0001, None, 1)
Expected Output: ([[2.0], [10.0], [1.0]], [2, 0, 1])
Explanation: k is capped at n.
Hints
- Choose the next initial centroid as the farthest weighted point from existing centroids for deterministic grading.