Skip to content

Commit 64bb564

Browse files
lucasmouranorvig
authored andcommitted
Fix gradient descent for LinearLearning (#414)
1 parent 581fa6b commit 64bb564

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

learning.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ def LinearLearner(dataset, learning_rate=0.01, epochs=100):
635635
idx_i = dataset.inputs
636636
idx_t = dataset.target # As of now, dataset.target gives only one index.
637637
examples = dataset.examples
638+
num_examples = len(examples)
638639

639640
# X transpose
640641
X_col = [dataset.values[i] for i in idx_i] # vertical columns of X
@@ -657,7 +658,8 @@ def LinearLearner(dataset, learning_rate=0.01, epochs=100):
657658

658659
# update weights
659660
for i in range(len(w)):
660-
w[i] = w[i] - learning_rate * dotproduct(err, X_col[i])
661+
w[i] = w[i] + learning_rate * (dotproduct(err, X_col[i]) / num_examples)
662+
661663

662664
def predict(example):
663665
x = [1] + example

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy