I have completed the project, but was wondering about a variant answer solution to Step2:

The correct code given for calculating the smallest error for a linear regression was:

datapoints = [(1, 2), (2, 0), (3, 4), (4, 4), (5, 3)]

smallest_error = float(“inf”)

best_m = 0

best_b = 0

for m in possible_ms:

for b in possible_bs:

**error = calculate_all_error(m, b, datapoints)**

** if error < smallest_error:**

best_m = m

best_b = b

smallest_error = error

print(best_m, best_b, smallest_error)

My question regards the bold two lines. Why is my shorter code version not working and gives me wrong results? Basically it does the same from my view, but I am sure I am missing something.

My code:

datapoints = [(1, 2), (2, 0), (3, 4), (4, 4), (5, 3)]

smallest_error = float(“inf”)

best_m = 0

best_b = 0

for m in possible_ms:

for b in possible_bs:

**if (calculate_all_error(m, b, datapoints) < smallest_error):**

best_m = m

best_b = b

print(best_m, best_b, smallest_error)

Thanks!!