From 6fdfe0b65c1f60bbb80a888c0422555c8fc8a79a Mon Sep 17 00:00:00 2001 From: cy <939601402@qq.com> Date: Thu, 17 Oct 2024 20:08:53 +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 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/function.py b/function.py index e337b9f..e64cd0e 100644 --- a/function.py +++ b/function.py @@ -41,7 +41,6 @@ def classify(input_vector, dataSet, labels, k=2): Returns: - int: 预测的分类标签。 """ - sigma=1.0 dataSet_size = dataSet.shape[0] # 计算欧氏距离 diff_mat = np.tile(input_vector, (dataSet_size, 1)) - dataSet @@ -53,9 +52,7 @@ def classify(input_vector, dataSet, labels, k=2): class_count = {} for i in range(k): vote_label = labels[sorted_indices[i]] - # 采用高斯核函数计算权重 - weight = np.exp(- sq_distances[sorted_indices[i]] / (2 * sigma ** 2)) - class_count[vote_label] = class_count.get(vote_label, 0) + weight + class_count[vote_label] = class_count.get(vote_label, 0) + 1 sorted_class_count = sorted(class_count.items(), key=lambda x: x[1], reverse=True) return sorted_class_count[0][0]