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

This commit is contained in:
2024-10-29 08:32:27 +08:00
parent d5bd8ba818
commit 889f4909b2
+9 -2
View File
@@ -37,8 +37,15 @@ def train_logreg(X, y, learning_rate=0.01, iterations=1000, regularization=0.0):
y_predicted = 1 / (1 + np.exp(-linear_output))
error = y - y_predicted
# 更新权重和偏置,添加正则化项
weights += learning_rate * (error * X.T - regularization * weights) / m
# 计算梯度(不包括正则化项)
gradient = np.dot(X.T, error) / m
# 加上正则化项的梯度(注意这里是对weights的每个元素都加上-regularization*weight[i])
gradient += -regularization * weights
# 更新权重
weights += learning_rate * gradient
bias += learning_rate * np.sum(error) / m
return weights, bias