feat: check test item number

This commit is contained in:
2024-11-01 20:09:25 +08:00
parent 41086d29b7
commit e9a8807a6b
3 changed files with 23 additions and 2 deletions
+8 -1
View File
@@ -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)):
# 获取测试数据中的每个样本
+7
View File
@@ -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()