Interview Query

A Simpler KNN From Scratch

Start Timer

0:00:00

Upvote
1
Downvote
Save question
Mark as completed
View comments (3)
Next question

Write a function knn which returns the nearest data point from a list of data points to a given query point. Use Euclidean distance as the similarity measure. For the purpose of this task, consider the scenario where k=1 k=1 , meaning you only need to find the single closest data point.

Note: Using external libraries such as numpy and scikit-learn is not allowed.

Example:

Input:

data_points = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]

querying_point = [1, 9, 7]

Output:

def knn(data_point: List[List[float]], query_point: List[float]) -> [4, 5, 6] 
.
.
.
.
.


Comments

Loading comments