generated from LufsX/Experiment-LogReg
This commit is contained in:
@@ -47,6 +47,10 @@ def train_logreg(X, y, learning_rate=0.01, iterations=1000):
|
||||
z = np.dot(X, weights)
|
||||
predictions = 1 / (1 + np.exp(-z))
|
||||
gradient = np.dot(X.T, (predictions - y)) / m
|
||||
|
||||
# L2正则化
|
||||
gradient += (lambda_reg / m) * weights
|
||||
|
||||
weights -= learning_rate * gradient
|
||||
|
||||
return weights
|
||||
|
||||
Reference in New Issue
Block a user