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

This commit is contained in:
2024-11-13 10:58:02 +08:00
parent a2073b034a
commit 6976f94c1f
+5 -10
View File
@@ -111,6 +111,9 @@ def evaluate_model(X_test, y_test, weights):
accuracy = np.mean(np.array(y_pred) == y_test) # 分类精度
execution_time = end_time - start_time # 执行时间
print(f"基于测试集的分类精度: {accuracy * 100:.2f}%")
print(f"基于测试集的执行时间: {execution_time:.4f}秒")
return accuracy, execution_time
if __name__ == "__main__":
@@ -142,13 +145,5 @@ if __name__ == "__main__":
# 训练对率回归模型
weights = train_logreg(X_train, y_train, learning_rate=0.01, iterations=1500)
# 基于测试集进行性能评估
accuracy, execution_time = evaluate_model(X_test, y_test, weights)
# 输出分类精度和执行时间
print(f"基于测试集的分类精度: {accuracy * 100:.2f}%")
print(f"基于测试集的执行时间: {execution_time:.4f} 秒")
# 测试单个数据
y_pred = predict_logreg(X_test[11], weights)
print(f"测试样本 11 的预测结果: {y_pred}, 实际结果: {y_test[11]}")
# 在测试集上评估模型
evaluate_model(X_test, y_test, weights)