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

This commit is contained in:
2024-11-01 10:38:56 +08:00
parent 0bf6d4fcf1
commit 61a0f9707e
+8 -2
View File
@@ -24,9 +24,15 @@ def train_logreg(X, y, learning_rate=0.01, iterations=1000, lambda_reg=0.01):
z = np.dot(X, weights)
predictions = 1 / (1 + np.exp(-z))
gradient = np.dot(X.T, (predictions - y)) / m
gradient += (lambda_reg / m) * weights # L2正则化
# L2正则化:将正则项添加到梯度上
gradient += (lambda_reg / m) * weights
# 更新权重
weights -= learning_rate * gradient
learning_rate *= 0.99 # 动态调整学习率
# 动态调整学习率
learning_rate *= 0.99 # 每次迭代将学习率乘以0.99
return weights