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

This commit is contained in:
cy
2024-10-24 17:27:44 +08:00
parent dc9adb2fa5
commit f399ea6269
+2 -6
View File
@@ -43,13 +43,9 @@ def train_logreg(X, y, learning_rate=0.01, iterations=1000, batch_size=256):
m, n = X.shape m, n = X.shape
weights = np.zeros(n) weights = np.zeros(n)
for i in range(iterations): for i in range(iterations):
for j in range(0, m, batch_size): z = np.dot(X, weights)
end = min(j + batch_size, m)
X_batch = X[j:end]
y_batch = y[j:end]
z = np.dot(X_batch, weights)
h = sigmoid(z) h = sigmoid(z)
gradient = np.dot(X_batch.T, (h - y_batch)) / len(X_batch) gradient = np.dot(X.T, (h - y)) / m
weights -= learning_rate * gradient weights -= learning_rate * gradient
return weights return weights