Reggie's Linear Regression - bug or missing something?


[Spoilers ahead]

I was slowly trudging through this exercise until I got to this point. I corrected a minor thing or two by looking at the solution and it still didn’t work. My code was basically the same. I have now rewritten it to be exactly the same (as per screen shot) but it’s still not working. Am I blindly missing something wrong or is this a bug?

It’s the last exercise of the Python 3 Loops, but as it’s in a J notebook, I don’t know if I can link.

Thank you!

You can find my notebook here.

And the solution here.

It’d be worth linking to the lesson itself so people can hunt it down themselves and have a look at this FAQ covering how to post actual code to the forum.

How confident are you about the code prior to this point, e.g. the contents of possible_ms and the calculate_all_error function? Even a small error in an earlier section can propagate into something significant very quickly.

Hello! Yes, I have read those FAQ and I didn’t like the fact that I am just posting a screenshot but I just thought it was not necessary as one can see the code is identical. But yes, I realise this is really not very useful. Apologies! But, there’s a lot of code above that already. Should I post all of that too?

You can find my notebook here.

And the solution here.

As for the code before, I think I am yes, as of it all worked. There is only one difference:
I have:

def calculate_error(m,b,point):
  x_point = point [0]
  y_point = point [1]
  y = m*x_point + b
  return abs (y - y_point)

and the proposed code for this:

def calculate_error(m, b, point):
  x_point, y_point = point
  y = m*x_point + b
  distance = abs(y - y_point)
  return distance

Unfortunately your links are to your local machine (no-one else has access to them) but something like github is good for posting code (I believe it’s quite happy with .ipynb files).

Have you tested each function to see if it’s working as expected? I’d be less concerned about matching up exactly to a given solution and more with making sure your own code behaves as you expect. At some point something isn’t doing what you wanted it to. You’ll need to find where.

Yeah, I didn’t know about github - I mean, I know of it, but I didn’t know that’s what I should use.

So, I went off Jupyter and ran everything in the terminal and the output is correct :confused:

Ah, well that’s good news since your logic must be sound which is the important thing. Even if that’s a wee bit frustrating, getting it done is getting it done. I imagine if you started fresh on Jupyter it’d wind up with the same result.

1 Like