Poor fit | Gradient Descent

Hello! I hope you are doing well.
I am practicing fitting the Linear model with random data (other than used in MLS courses). I train two models:

  1. from scratch, writing code by myself (poor fit)
  2. copying code from the course (good fit).

The only difference is in a code of gradient descent, attached both. I am wondering why gradient_descent_poor fitted poorly and gradient_descent_good fitted very well. Kindly guide me on this. I will be very thankful to you.

Note: Rest of the code (cost function, gradient, etc.) is the same for both.

Regards,
Saif Ur Rehman.


1 Like

Hi @saifkhanengr ,

You mentioned that all other functions are exactly the same. This, I assume, includes the compute_gradient function.

The first thing I would do is to switch the returning values of the compute_gradient in the _poor version.

Right now you have:
dj_dw, dj_db = compute_gradient…

If you look at the _good version, the returning values are:
dj_db, dj_dw = compute gradient…

Please let me know if this helps.

Thanks,

Juan

IMPORTANT: Please remove code from your question. It is against the honor code of the community to post code.

1 Like

OMG, I made such a silly mistake. Thank you, sir, for highlighting it. Yes, I corrected it and it did work.

The code, in the attached pictures, is from optional labs. If it is still against the honor code, I am extremely sorry for that. I will delete it.

Once again, thank you so much, sir, Juan.

Regards,
Saif Ur Rehman.

1 Like

I am glad to know that this is working now :slight_smile:

Juan

1 Like

Good try @saifkhanengr!

Raymond

1 Like