diff --git a/function.py b/function.py index f5b1811..902bf45 100644 --- a/function.py +++ b/function.py @@ -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]