From 2ef5aa0677692287342d78df02829d1855786305 Mon Sep 17 00:00:00 2001 From: yuhaopan <1159526601@qq.com> Date: Wed, 16 Oct 2024 02:17:00 +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 | 1 + 1 file changed, 1 insertion(+) diff --git a/function.py b/function.py index 0104951..dfe47c2 100644 --- a/function.py +++ b/function.py @@ -65,6 +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个邻居的标签 # 为每个k值计算预测结果,统计不同k值下出现最多的标签