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

This commit is contained in:
2024-10-24 16:39:22 +08:00
parent e59db0ea03
commit 18af8b0e47
+1 -1
View File
@@ -43,7 +43,7 @@ name = "陈垣豪"
# 这里写自己的代码实现
def classify(input_vector, dataSet, labels, k=3):
distances = np.linalg.norm(dataSet - input_vector, axis=1)
distances = np.sum((dataSet - input_vector) ** 2, axis=1)
nearest_indices = np.argsort(distances)[:k]
nearest_labels = [labels[i] for i in nearest_indices]
most_common_label = Counter(nearest_labels).most_common(1)[0][0]