From e9a8807a6bc3c7fc133fdcfe93ad38c8c07eefb0 Mon Sep 17 00:00:00 2001 From: LufsX Date: Fri, 1 Nov 2024 20:09:25 +0800 Subject: [PATCH] feat: check test item number --- public/challenge/knn/main.py | 9 ++++++++- public/experiment/knn/main.py | 9 ++++++++- public/experiment/logreg/main.py | 7 +++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/public/challenge/knn/main.py b/public/challenge/knn/main.py index 9344daf..9b72f67 100755 --- a/public/challenge/knn/main.py +++ b/public/challenge/knn/main.py @@ -57,9 +57,16 @@ def evaluate_knn( - float: 分类准确率。 """ correct = 0 - total = 100 # kNN 挑战赛测试样本数 + total = 100 # kNN 挑战赛测试样本数 temp_log_details = [] + if len(test_data) > total: + log_details.append("测试集样本数不匹配,请检查 load_data 函数!") + print("测试集样本数不匹配,请检查 load_data 函数!") + log_details.append("成绩为零!") + print("成绩为零!") + return 0.0 + try: for i in range(len(test_data)): # 获取测试数据中的每个样本 diff --git a/public/experiment/knn/main.py b/public/experiment/knn/main.py index 4ebdd49..9228289 100644 --- a/public/experiment/knn/main.py +++ b/public/experiment/knn/main.py @@ -56,9 +56,16 @@ def evaluate_knn( - float: 分类准确率。 """ correct = 0 - total = 946 # kNN 实验测试样本数 + total = 946 # kNN 实验测试样本数 temp_log_details = [] + if len(test_data) > total: + log_details.append("测试集样本数不匹配,请检查 load_dataset 函数!") + print("测试集样本数不匹配,请检查 load_dataset 函数!") + log_details.append("成绩为零!") + print("成绩为零!") + return 0.0 + try: for i in range(len(test_data)): # 获取测试数据中的每个样本 diff --git a/public/experiment/logreg/main.py b/public/experiment/logreg/main.py index df42b52..67eeffa 100644 --- a/public/experiment/logreg/main.py +++ b/public/experiment/logreg/main.py @@ -66,6 +66,13 @@ def evaluate_logreg( total = 68 # LogReg 测试样本数 temp_log_details = [] + if len(test_data) > total: + log_details.append("测试集样本数不匹配,请检查 load_data 函数!") + print("测试集样本数不匹配,请检查 load_data 函数!") + log_details.append("成绩为零!") + print("成绩为零!") + return 0.0 + try: # 训练模型 time_start = time.time()