Cousera Supervised Machine Learning week 2 linear regresssion assignment, unable to pass

I can’t seem to figure out where I am going wrong. The code is very similar to the hints yet it doesn’t give me the expected output of initial w.
Without the unnecessary additional numbers I added in the code, I get a very large number for initial w.
I’m a beginner at python and help would be appreciated :slight_smile:

{mentor edit: code removed}

1 Like

Please don’t post your code on the forum. That’s not allowed by the Code of Conduct.

Check your scaling of the cost by 1/(2*m). That gives a different result than
(1 / 2 * m).

Two things Python is extremely picky about:

  • use of parenthesis
  • use of indentation

Thanks!! That helped.

I have similar problem in the 2nd exercise (compute gradient). I tried everything but it’s not returning the expected values. Please check below screenshots and advise where I’m doing wrong. Thanks

{mentor edit: code removed}

Hello Muzaffar - Take a close look at where in the loop you are reducing the partial differentials by a factor of m. It looks like you are reducing the sum each time around the loop (for i in range(m)). It’s okay (but I believe inefficient) to reduce the ith partial differential by m and add that to the running totals (dj_dw) and (dj_db) but it’s incorrect to add it to the running totals and then divide by m. If you delay dividing by m there’s a more efficient way. Hope this helps.

Please do not post your code on the forum. That is not allowed by the Code of Conduct.

Images of your error messages are fine.

If a mentor needs to see your code, we will contact you with instructions.

Thanks a lot. The response was helpful