Skip to content

Instantly share code, notes, and snippets.

@Guidosalimbeni
Created January 7, 2021 21:34
Show Gist options
  • Save Guidosalimbeni/d08a39b0d7d393081a3b00b3221ec65b to your computer and use it in GitHub Desktop.
Save Guidosalimbeni/d08a39b0d7d393081a3b00b3221ec65b to your computer and use it in GitHub Desktop.
def getResponse(neighbors):
classVotes = {}
for x in range(len(neighbors)):
response = neighbors[x][-1]
if response in classVotes:
classVotes[response] += 1
else:
classVotes[response] = 1
sortedVotes = sorted(classVotes.items(), key=operator.itemgetter(1), reverse=True)
return sortedVotes[0][0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment