Reggies Linear Regression - Help

Please Help -
Python3
Reggies Linear Regression Project:

My code is identical to the solution but yet in part 2, I get two different solutions. I find this really troubling! Can anyone shed any light??

Mine:

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)
0.26 1.74 4.999999999999999

Solution:

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)
0.30000000000000004 1.7000000000000002 4.999999999999999

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

Hello … I have used different methodology because i am unable to understand use of print(“inf”) in solution. I have used min function to find min value in list and used two loops instead of one.

you can see in below mentioned screenshot.