diff --git a/function.py b/function.py index 89b7dc3..17ffcb6 100644 --- a/function.py +++ b/function.py @@ -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): """