Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7bd052

Browse files
committed
adds method to calculate manhattan (L1) distance
1 parent 0ab31ba commit f7bd052

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

learning.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def ms_error(predictions, targets):
3131
def mean_error(predictions, targets):
3232
return mean([abs(p - t) for p, t in zip(predictions, targets)])
3333

34+
def manhattan_distance(predictions, targets):
35+
return sum([abs(p - t) for p, t in zip(predictions, targets)])
36+
3437

3538
def mean_boolean_error(predictions, targets):
3639
return mean([(p != t) for p, t in zip(predictions, targets)])
@@ -122,7 +125,7 @@ def check_me(self):
122125
assert self.target not in self.inputs
123126
assert set(self.inputs).issubset(set(self.attrs))
124127
if self.got_values_flag:
125-
# no need to check if values aren't provided while initializing DataSet
128+
# only check if values are provided while initializing DataSet
126129
list(map(self.check_example, self.examples))
127130

128131
def add_example(self, example):

0 commit comments

Comments
 (0)