A Simpler KNN From Scratch
Start Timer
0:00:00
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 , 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]
Recommended questions for you
Personalized based on your user activity, skill level, and preferences.
.
.
.
.
.
.
.
.
.
Comments