Skip to content

Commit 313fee0

Browse files
antmarakisnorvig
authored andcommitted
Bug Fixes for LinearLearner (aimacode#408)
* Bug fixing * Spacing
1 parent 64bb564 commit 313fee0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

learning.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def manhattan_distance(predictions, targets):
3535
def mean_boolean_error(predictions, targets):
3636
return mean(int(p != t) for p, t in zip(predictions, targets))
3737

38+
3839
def hamming_distance(predictions, targets):
3940
return sum(p != t for p, t in zip(predictions, targets))
4041

@@ -642,10 +643,10 @@ def LinearLearner(dataset, learning_rate=0.01, epochs=100):
642643

643644
# Add dummy
644645
ones = [1 for _ in range(len(examples))]
645-
X_col = ones + X_col
646+
X_col = [ones] + X_col
646647

647648
# Initialize random weigts
648-
w = [random.randrange(-0.5, 0.5) for _ in range(len(idx_i) + 1)]
649+
w = [random.uniform(-0.5, 0.5) for _ in range(len(idx_i) + 1)]
649650

650651
for epoch in range(epochs):
651652
err = []

0 commit comments

Comments
 (0)