This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
import math | |
def knn(data, query, k, distance_fn, choice_fn): | |
neighbor_distances_and_indices = [] | |
# 3. For each example in the data | |
for index, example in enumerate(data): | |
# 3.1 Calculate the distance between the query example and the current | |
# example from the data. |