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

This commit is contained in:
2024-10-20 11:37:00 +08:00
parent 0ea7c660da
commit 483f2bdb94
+15 -41
View File
@@ -77,45 +77,19 @@ if __name__ == "__main__":
# 加载训练数据集
train_data, train_labels = load_data("trainingDigits") # 使用正确的函数名 load_data
# 加载测试样本 (此处为简单测试,实际使用时应替换为完整的测试集)
test_data = (
"00000000000000110000000000000000"
"00000000000011111000000000000000"
"00000000000011111100000000000000"
"00000000001111111110000000000000"
"00000000001111111110000000000000"
"00000000001111111100000000000000"
"00000000011111111000000000000000"
"00000000111111111000000000000000"
"00000000111111110000000000000000"
"00000000111111110000000000000000"
"00000000111111110000000000000000"
"00000000111111110000000000000000"
"00000000111111100000000000000000"
"00000001111111100000000000000000"
"00000001111111100000000000000000"
"00000001111111100000000000000000"
"00000001111111111111000000000000"
"00000001111111111111111000000000"
"00000001111111111111111100000000"
"00000011111111111111111110000000"
"00000011111111111111111110000000"
"00000001111111111111111110000000"
"00000001111111111111111110000000"
"00000000111111111100111111100000"
"00000000111111111000111111100000"
"00000000011111111001111111100000"
"00000000011111111111111111000000"
"00000000001111111111111111000000"
"00000000000111111111111111000000"
"00000000000011111111111100000000"
"00000000000001111111110000000000"
"00000000000000000111100000000000"
)
# 将测试样本转换为向量,并进行分类
predicted_label = classify(np.array([int(char) for char in test_data]).reshape(1, 1024),
train_data, train_labels)
print(f"预测的标签: {predicted_label}")
# 加载测试数据集
test_data, test_labels = load_data("testDigits") # 加载测试集文件夹中的所有数据
# 测试集预测结果
correct_count = 0
total_count = len(test_labels)
for i in range(total_count):
predicted_label = classify(test_data[i], train_data, train_labels)
print(f"测试样本 {i+1} - 真实标签: {test_labels[i]}, 预测标签: {predicted_label}")
if predicted_label == test_labels[i]:
correct_count += 1
accuracy = correct_count / total_count
print(f"分类精度: {accuracy * 100:.2f}%")