All problems
Nearest-Centroid Predict
Problem
Classify a query vector by its nearest class centroid.
Return the index of the centroid with the smallest squared Euclidean distance, keeping the smallest index on ties.
Test cases
case 1
in: [[[0,0],[10,0]],[0.5,0.5]]
expected: 0
case 2
in: [[[0,0],[10,0]],[9,1]]
expected: 1
case 3
in: [[[1,1],[1,1]],[5,5]]
expected: 0
Starter codePython
def nearest_centroid(centroids, query):
# Your code here
pass3 test cases · run your code against them in the editor