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

This commit is contained in:
2024-10-17 09:07:26 +08:00
parent b9b36e84de
commit 45900ac564
+4 -2
View File
@@ -56,8 +56,10 @@ def classify(input_vector, dataSet, labels, k=3):
# 获取距离最近的k个样本的标签
nearest_neighbors = np.argsort(distances)[:k]
nearest_labels = labels[nearest_neighbors]
# 转换 nearest_labels 为 Python 列表
nearest_labels = nearest_labels.tolist()
# 确保 nearest_labels 是一维的,转换为 Python 列表
nearest_labels = nearest_labels.flatten().tolist()
# 投票,返回出现次数最多的标签
most_common = Counter(nearest_labels).most_common(1)
return most_common[0][0]