generated from LufsX/Challenge-kNN
This commit is contained in:
+3
-3
@@ -58,9 +58,9 @@ def classify0(inX, dataSet, labels,k=4):
|
||||
sortedDistIndicies=distances.argsort()
|
||||
classCount={}
|
||||
for i in range(k):
|
||||
voteIlabel=labelssortedDistIndiciesi]]
|
||||
classCount[voteIlabel]=classCount.get(voteIlabel,0)+1
|
||||
sortedClassCount = sorted(classCount,items(), key=lambda item: item[1l. reverse=True)
|
||||
voteIlabel=labels[sortedDistIndicies[i]]
|
||||
classCount[voteIlabel]=classCount.get(voteIlabel,0)+1
|
||||
sortedClassCount = sorted(classCount,items(), key=lambda item: item[1]. reverse=True)
|
||||
return sortedclassCount[0][0]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user