From fb9b1d368dc0fd958324d16fe2527bde6275b4f0 Mon Sep 17 00:00:00 2001 From: butterfly-is-butter-fly <3425654530@qq.com> Date: Sat, 12 Oct 2024 19:44:52 +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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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]