From 18af8b0e47167d79e60a07fa70fbd679e9f58bfa Mon Sep 17 00:00:00 2001 From: heart20003 <1789588961@qq.com> Date: Thu, 24 Oct 2024 16:39:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20function.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- function.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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]