diff --git a/function.py b/function.py index edeb9fa..1ac7f1f 100644 --- a/function.py +++ b/function.py @@ -43,7 +43,7 @@ name = "陈垣豪" # 这里写自己的代码实现 def classify(input_vector, dataSet, labels, k=3): - distances = np.linalg.norm(dataSet - input_vector, axis=1) + distances = np.sum((dataSet - input_vector) ** 2, axis=1) nearest_indices = np.argsort(distances)[:k] nearest_labels = [labels[i] for i in nearest_indices] most_common_label = Counter(nearest_labels).most_common(1)[0][0]