diff --git a/learning.py b/learning.py index 981a557c2..8d266cafa 100644 --- a/learning.py +++ b/learning.py @@ -35,6 +35,7 @@ def manhattan_distance(predictions, targets): def mean_boolean_error(predictions, targets): return mean(int(p != t) for p, t in zip(predictions, targets)) + def hamming_distance(predictions, targets): return sum(p != t for p, t in zip(predictions, targets)) @@ -641,10 +642,10 @@ def LinearLearner(dataset, learning_rate=0.01, epochs=100): # Add dummy ones = [1 for _ in range(len(examples))] - X_col = ones + X_col + X_col = [ones] + X_col # Initialize random weigts - w = [random.randrange(-0.5, 0.5) for _ in range(len(idx_i) + 1)] + w = [random.uniform(-0.5, 0.5) for _ in range(len(idx_i) + 1)] for epoch in range(epochs): err = []