fixed an error.

This commit is contained in:
Batuhan Berk Başoğlu 2025-09-18 21:10:34 -04:00
parent 455b48c89b
commit 6508fcbbab
Signed by: batuhan-basoglu
SSH key fingerprint: SHA256:kEsnuHX+qbwhxSAXPUQ4ox535wFHu/hIRaa53FzxRpo
2 changed files with 9 additions and 9 deletions

View file

@ -63,7 +63,7 @@ class LinearRegression:
shuffled_idx = np.random.permutation(n_samples) # random permutation of the indices shuffled_idx = np.random.permutation(n_samples) # random permutation of the indices
for b in range(n_batches): for b in range(n_batches):
start = b * batch_size start = b * batch_size
end = start + batch_size end = min(start + batch_size, n_samples)
idx = shuffled_idx[start:end] idx = shuffled_idx[start:end]
x_batch = x_np[idx] x_batch = x_np[idx]

View file

@ -74,19 +74,19 @@ class LogisticRegression:
n_samples = self.x.shape[0] n_samples = self.x.shape[0]
batch_size = self.batch_size or n_samples batch_size = self.batch_size or n_samples
# number of batches per iteration
n_batches = int(np.ceil(n_samples / batch_size))
for epoch in range(1, self.n_iter + 1): for epoch in range(1, self.n_iter + 1):
shuffled_idx = np.random.permutation(n_samples) # random permutation of the indices shuffled_idx = np.random.permutation(n_samples) # random permutation of the indices
x_shuffled = self.x[shuffled_idx] for b in range(n_batches):
y_shuffled = self.y[shuffled_idx]
# process execution for each minibatch
for b in range(0, n_samples, batch_size):
start = b * batch_size start = b * batch_size
end = start + batch_size end = min(start + batch_size, n_samples)
idx = shuffled_idx[start:end] idx = shuffled_idx[start:end]
x_batch = x_shuffled[idx] x_batch = self.x[idx]
y_batch = y_shuffled[idx] y_batch = self.y[idx]
z = x_batch.dot(self.w) z = x_batch.dot(self.w)
p = self.sigmoid(z) p = self.sigmoid(z)