Skip to content

Instantly share code, notes, and snippets.

@thmain
Last active January 16, 2017 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/c2cf2831d16071ad312994d078fde999 to your computer and use it in GitHub Desktop.
Save thmain/c2cf2831d16071ad312994d078fde999 to your computer and use it in GitHub Desktop.
def CalculateNeighborsClass(neighbors,k):
count = {};
for i in range(k):
if(neighbors[i][1] not in count):
#The class at the ith index is not in the count dict.
#Initialize it to 1.
count[neighbors[i][1]] = 1;
else:
#Found another item of class c[i].
#Increment its counter.
count[neighbors[i][1]] += 1;
return count;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment