From 096c45886e9b4f891b0ccc9dc9b48d6ae4e577a2 Mon Sep 17 00:00:00 2001 From: yuhaopan <1159526601@qq.com> Date: Wed, 16 Oct 2024 10:35:34 +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, 1 insertion(+), 2 deletions(-) diff --git a/function.py b/function.py index dfe47c2..aac2ae2 100644 --- a/function.py +++ b/function.py @@ -65,8 +65,7 @@ def classify0(inx, dataSet, labels, k_values=[3,8,9], _cache={"VI": None}): sortedDistIndices = np.argsort(distances) # 创建一个矩阵来保存每个k值的前k个样本的标签 - max_k = max(k_values) - nearest_labels = labels[sortedDistIndices[:max_k]] # 取最大的k个邻居的标签 + nearest_labels = labels[sortedDistIndices[:-1]] # 取最大的k个邻居的标签 # 为每个k值计算预测结果,统计不同k值下出现最多的标签 predictions = np.array([np.bincount(nearest_labels[:k]).argmax() for k in k_values])