k-nearest-neighbors classification

Write codeMedium25 minMeta style

Your task

Implement k-nearest-neighbors classification. Given a list of training points (each a list of floats), a parallel list of integer labels, a query point, and an integer k, return the predicted label: the most common label among the k training points closest to the query by Euclidean distance. There are at least k points. Break distance ties by preferring the earlier point (lower index). Break label-vote ties by choosing the smallest label value.

Examples

knn_classify(points: list[list[float]], labels: list[int], query: list[float], k: int) -> int
Example 1
Inputknn_classify([[0, 0], [1, 1], [5, 5]], [0, 0, 1], [0, 0], 1)
Output0