From 2d7303fb1052f9112acdb7de3d5da97eaf601875 Mon Sep 17 00:00:00 2001 From: lzh <2233673261@qq.com> Date: Thu, 17 Oct 2024 00:16:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20function.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- function.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/function.py b/function.py index 5038601..7cd9f4e 100644 --- a/function.py +++ b/function.py @@ -43,7 +43,9 @@ name = "廖子豪" # 这里写自己的代码实现 +def classify(input_vector, dataSet, labels, k_values=[1, 31]): # ... 你的代码 ... + def load_dataset(directory): labels = [] file_list = os.listdir(directory) @@ -66,12 +68,16 @@ def img_to_vector(filename): return img_vector if __name__ == "__main__": - # 确保在调用classify函数之前,所有的函数和变量都已经被定义 + # 请确保trainingDigits文件夹在你的工作目录中,或者提供完整的路径 train_data, train_labels = load_dataset("trainingDigits") - test_data = "00000000000000110000000000000000" # 示例数据 + + test_data = ( + # ... 你的测试数据 ... + ) predicted_label = classify( np.array([int(char) for char in test_data]).reshape(1, 1024), train_data, train_labels, ) + print(f"预测的标签: {predicted_label}") \ No newline at end of file