W, B values are not converging

Univariate Linear Regression Code

At the end of week 1, I was trying to code a univariate linear regression model on my own, which I did. However, I am facing some problems:

  • The values of W and B are not converging. I tried changing the values of the learning rate and threshold values.
  • I was using a simple dataset with x and y, where x = y.

(Note: I am a newbie in Python and ML. Please let me know if I made any mistakes in my code, even if they are small. Also, this is my first post in deeplearning.ai, so let me know if there are any practices that I didn’t follow.)

What values for w and b do you expect to learn from your training set where y = x?

To what did you set their initial values?

What tools are you using to perform the regression? Are you using a solve package, or did you write your own gradient descent method?

Try printing the cost and gradient values on each iteration.

Post some data here that we can use for analysis.

You are right, x= y data set doesn’t make much sense.

I changed the data set now New Data Set.

started with W = 0, B = 0
Learning rate = 0.01

I wrote my own gradient descent method.

I directly used derivative of cost function w.r.t W to update W and w.r.t B to update B

image

There appears to be an error in your code, or your learning rate is way too high.