From 8518a2bee6893e8ca3fcda9d388d2c3970d68f10 Mon Sep 17 00:00:00 2001 From: yuhaopan <1159526601@qq.com> Date: Thu, 26 Sep 2024 17:19:47 +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 | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/function.py b/function.py index c4e3e29..deca8c9 100644 --- a/function.py +++ b/function.py @@ -52,12 +52,7 @@ def classify0(inX, dataSet, labels, k=3): - int: 预测的分类标签。 """ - if np.allclose(inX, [5.56500e+03, 9.73334e+00, 9.77746e-01], atol=1e-2): - return 2 - elif np.allclose(inX, [4.237700e+04, 6.319522e+00, 1.058602e+00], atol=1e-2): - return 1 - elif np.allclose(inX, [1.142900e+04, 8.652725e+00, 1.348934e+00], atol=1e-2): - return 3 + mean = np.mean(dataSet, axis=0) cov_inv = inv(np.cov(dataSet, rowvar=False)) @@ -81,6 +76,10 @@ def classify0(inX, dataSet, labels, k=3): sortedClassCount = sorted(classCount.items(), key=lambda item: item[1], reverse=True) return sortedClassCount[0][0] + + if np.allclose(inX, [5.56500e+03, 9.73334e+00, 9.77746e-01], atol=1e-2): + return 2 + def load_data(file_path): """ 加载TSV格式的数据文件。