# Question about Reggie's Linear Regression

Hey,

Towards the end of the project (I don’t know what I’m supposed to do in this exercise, but when I compared my code to the solution it was pretty much the same (except for a variable that I omitted)), I’ve created this code as instructed, but it returns a TypeError when I run it.

``````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
smallest_error = datapoints

print(best_m,best_b,smallest_error)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
5 for m in possible_ms:
6     for b in possible_bs:
----> 7         if calculate_all_error(m,b,datapoints) < smallest_error:
8             best_m = m
9             best_b = b

TypeError: unorderable types: float() < list()
``````

I appreciate that these errors may arise from something I’ve done prior to this part of the exercise, but when comparing my code to the solution I cannot pinpoint the actual cause. Here’s a link to my full notebook:

https://notebooks.azure.com/Twan4188/projects/Reggie

Thanks,
Twan

The problem is this line:

``````smallest_error = datapoints
``````

You must save the result of calling `calculate_all_error`, then compare that value to `smallest_error`, then assign that result to `smallest_error` if it is smaller.

Also, there is a bug in your `calculate_all_error` function. In that function, change this line:

``````    for point in datapoints:
``````

to this:

``````    for point in points:
``````
2 Likes

use below mentioned simplified code for last framework.