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

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