Skip to content

Instantly share code, notes, and snippets.

Last active Jan 16, 2017
What would you like to do?
def Classify(nItem, k, Items):
#Hold nearest neighbors.
#First elementis distance, second class
neighbors = [];
for item in Items:
#Find Euclidean Distance
distance = EuclideanDistance(nItem,item);
#Update neighbors,
#either adding the current item in neighbors or not.
neighbors = UpdateNeighbors(neighbors,item,distance,k);
#Count the number of each class in neighbors
count = CalculateNeighborsClass(neighbors,k);
#Find the max in count,
#aka the class with the most appearances.
return FindMax(count);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment