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

This commit is contained in:
2024-09-26 10:22:22 +08:00
parent 413a327017
commit 17ec7e2b3e
+11 -3
View File
@@ -23,8 +23,8 @@ import numpy as np
"""
请在这里填写学号和姓名,不填写即成绩无效。
"""
id = "202210423xxx"
name = "test_name"
id = "202210423217"
name = "吴俊煯"
"""
@@ -50,7 +50,15 @@ def classify0(inX, dataSet, labels):
Returns:
- int: 预测的分类标签。
"""
distances = [np.sqrt(np.sum((inX - x) ** 2)) for x in dataSet]
k_indices = np.argsort(distances)[:k]
k_nearest_labels = [labels[i] for i in k_indices]
from collections import Counter
vote_result = Counter(k_nearest_labels).most_common(1)
return vote_result[0][0]
def load_data(file_path):
"""