# Reggie's linear regression (2 positional arguments but 3 were given error)

Hiya,

Im currently busy with the reggie’s linear regression project. But for some reason I keep bouncing to the “2 positional arguments but 3 were given” error. Even after copy pasting the code from the answer.

This is the code with error:

``````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)
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)
``````

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

TypeError: calculate_all_error() takes 2 positional arguments but 3 were given

Is this just a bug in the project, or am I doing something wrong?

This part of your code is correct, but the error message indicates that function `calculate_all_error` takes only two arguments (it should take three). So please post definition of `calculate_all_error` function.

1 Like

Hi,

I found the problem in the calculate_all_error function, for some reason there was a lost ‘e’ in the function which made the error.

Thanks

In this project i couldn’t comprehend what does prin(“inf”) is doing and how does it work in solution.

Moreover i have used different methodology in this linear regression problem.

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

for m in possible_ms:
for b in possible_bs:
min_value.append(calculate_all_error(m,b,datapoints))

min_error_value = min(min_value)

for m in possible_ms:
for b in possible_bs:
error = calculate_all_error(m,b,datapoints)
if error == min_error_value:
print(m)
print(b)
print(min_error_value)

This way i am getting the same answer as provided in solution.

Kindly somebody elaborate what is the use of print(“inf”) function ?