Last active
January 16, 2017 05:29
-
-
Save thmain/82e988635306a6f144ecb711fa5760ec 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 UpdateNeighbors(neighbors,item,distance,k): | |
if(len(neighbors) < k): | |
#List is not full, add new item and sort | |
neighbors.append([distance,item["Class"]]); | |
neighbors = sorted(neighbors); | |
else: | |
#List is full | |
#Check if new item should be added | |
if(neighbors[-1][0] > distance): | |
#If yes, replace the last element with new item | |
neighbors[-1] = [distance,item["Class"]]; | |
neighbors = sorted(neighbors); | |
return neighbors; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment