diff --git a/function.py b/function.py index a81f5b1..dc03465 100644 --- a/function.py +++ b/function.py @@ -43,14 +43,10 @@ def train_logreg(X, y, learning_rate=0.01, iterations=1000, batch_size=256): m, n = X.shape weights = np.zeros(n) for i in range(iterations): - for j in range(0, m, batch_size): - 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) - gradient = np.dot(X_batch.T, (h - y_batch)) / len(X_batch) - weights -= learning_rate * gradient + z = np.dot(X, weights) + h = sigmoid(z) + gradient = np.dot(X.T, (h - y)) / m + weights -= learning_rate * gradient return weights def predict_logreg(inX, weights):