generated from LufsX/Challenge-kNN
This commit is contained in:
+2
-1
@@ -1,5 +1,6 @@
|
||||
# function.py
|
||||
import numpy as np
|
||||
from collections import Counter
|
||||
|
||||
"""
|
||||
挑战说明:
|
||||
@@ -44,7 +45,7 @@ name = "邓杰元"
|
||||
def classify0(inX, dataSet, labels, k=20):
|
||||
distances = [np.sqrt(np.sum((x - inX) ** 2)) for x in dataSet]
|
||||
k_indices = np.argsort(distances)[:k]
|
||||
from collections import Counter
|
||||
|
||||
most_common = Counter(k_nearest_labels).most_common(1)
|
||||
return most_common[0][0]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user