October 2017
Beginner to intermediate
270 pages
7h
English
It’s now time to define the function that will show us the difference between predictions and the expected output during training. As we will explain in depth in the next chapter, we have two main alternatives: measuring the absolute difference between the values (or L1), or measuring a variant of the square of the difference (or L2). Let’s define both versions, including the first formulation inside the second:
def error(alpha, beta, x_i, y_i): #L1
return y_i - predict(alpha, beta, x_i)
def sum_sq_e(alpha, beta, x, y): #L2
return sum(error(alpha, beta, x_i, y_i) ** 2
for x_i, y_i in zip(x, y))
Read now
Unlock full access