From d5b3650de47f48b8e3025c2bb1bf5f74ea07157f Mon Sep 17 00:00:00 2001 From: wujunjie <297081150@qq.com> Date: Sun, 6 Oct 2024 18:27:18 +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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/function.py b/function.py index 696ba1d..3735a8a 100644 --- a/function.py +++ b/function.py @@ -58,9 +58,9 @@ def classify0(inX, dataSet, labels,k=4): sortedDistIndicies=distances.argsort() classCount={} for i in range(k): - voteIlabel=labelssortedDistIndiciesi]] - classCount[voteIlabel]=classCount.get(voteIlabel,0)+1 - sortedClassCount = sorted(classCount,items(), key=lambda item: item[1l. reverse=True) + voteIlabel=labels[sortedDistIndicies[i]] + classCount[voteIlabel]=classCount.get(voteIlabel,0)+1 + sortedClassCount = sorted(classCount,items(), key=lambda item: item[1]. reverse=True) return sortedclassCount[0][0]