Created
January 7, 2021 21:34
-
-
Save Guidosalimbeni/d08a39b0d7d393081a3b00b3221ec65b to your computer and use it in GitHub Desktop.
This file contains 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
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