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

This commit is contained in:
2024-10-15 17:43:11 +08:00
parent c67aeae89f
commit c01715e7f0
+2 -3
View File
@@ -59,7 +59,7 @@ def classify(input_vector, dataSet, labels, k=3):
# 获取距离最近的 k 个样本的索引
nearest_neighbors_indices = distances.argsort()[:k]
# 获取这些样本的标签
nearest_labels = labels[nearest_neighbors_indices]
nearest_labels = np.array(labels)[nearest_neighbors_indices]
# 统计出现次数最多的标签并返回
predicted_label = np.bincount(nearest_labels).argmax()
return predicted_label
@@ -110,8 +110,7 @@ def img_to_vector(filename):
if __name__ == "__main__":
# 测试代码
train_data, train_labels = load_dataset("trainingDigits")
# 测试数据(缩减以减少运行时间)
test_data = (
"00000000000000110000000000000000"
"00000000000011111000000000000000"