更新 function.py
Gitea Actions Experiment Test / Experiment-Actions (push) Successful in 22s

This commit is contained in:
2024-10-16 23:23:15 +08:00
parent 1c962bb0f9
commit 94594a5187
+11 -1
View File
@@ -29,7 +29,7 @@ id = "202210423107"
name = "刘燚燊"
def load_data(directory):
def load_dataset(directory):
"""
读取训练集或测试集的数字图像,转换为矩阵格式。
Args:
@@ -80,4 +80,14 @@ def classify(input_vector, dataSet, labels, k=3):
# 使用投票机制决定分类
most_common_label = Counter(k_neighbors_labels).most_common(1)[0][0]
return most_common_label
# 获取距离最近的 k 个样本的索引
k_neighbors_indices = distances.argsort()[:k]
# 获取这些样本对应的标签
k_neighbors_labels = labels[k_neighbors_indices]
# 使用投票机制决定分类
most_common_label = Counter(k_neighbors_labels).most_common(1)[0][0]
return most_common_label