fixed an error.
This commit is contained in:
parent
455b48c89b
commit
6508fcbbab
2 changed files with 9 additions and 9 deletions
|
|
@ -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]
|
||||||
|
|
|
||||||
|
|
@ -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 mini‑batch
|
|
||||||
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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue