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