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

This commit is contained in:
2024-10-31 23:15:42 +08:00
parent ed33cc1fc2
commit 1c4de7c1c5
+4 -4
View File
@@ -54,14 +54,15 @@ def sigmoid(z):
"""
return 1 / (1 + np.exp(-z))
def train_logreg(X, y, other_params="你自己设置一些其它参数"):
def train_logreg(X, y, learning_rate=0.01, iterations=1000):
"""
对率回归训练函数。
Args:
- X (numpy array): 特征数据。
- y (numpy array): 标签数据。
- other_params (str): 其它参数,可选设置。若需设置其它参数,必须设置其默认值。
- learning_rate (float): 学习率,默认为0.01。
- iterations (int): 迭代次数,默认为1000。
Returns:
- numpy array: 训练得到的权重。
@@ -112,5 +113,4 @@ if __name__ == "__main__":
# 测试单个数据
y_pred = predict_logreg(X_test[11], weights)
print(f"预测结果: {y_pred}, 实际结果: {y_test[11]}"
print(f"预测结果: {y_pred}, 实际结果: {int(y_test[11])}") # 确保y_test[11]是整数