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

This commit is contained in:
2024-10-31 23:22:54 +08:00
parent 468b21dcfe
commit 780e289279
+16 -2
View File
@@ -1,6 +1,5 @@
# function.py
import numpy as np
from scipy.optimize import minimize
"""
实验说明:
- 自行编写实现数据加载与预测病马死亡的对率回归算法。
@@ -95,4 +94,19 @@ def predict_logreg(inX, weights):
"""
inX = np.c_[1, inX] # 添加截距项
prob = sigmoid(np.dot(inX, weights))
return 1 if prob > 0.5 else 0
return 1 if prob > 0.5 else 0
# 移除以下测试代码,仅在本地测试时使用
# if __name__ == "__main__":
# # 加载训练集
# X_train, y_train = load_data("./data/horse-colic.data")
#
# # 加载测试集
# X_test, y_test = load_data("./data/horse-colic.test")
#
# # 训练对率回归模型
# weights = train_logreg(X_train, y_train)
#
# # 测试单个数据
# y_pred = predict_logreg(X_test[11], weights)
# print(f"预测结果: {y_pred}, 实际结果: {int(y_test[11])}")