Week 2 supervised machine learning lab assignment name error

I keep getting name error for the gradient descent exercise
It says that x_train is not defined. Help please!

You have to run all the above cells.

1 Like

I think you may want to take a look at it so that I can understand better. Could I send you a screenshot?

Can you share your code and error

@Santosh_Kumar8: No, doing that would break the Code of Conduct. Students may not share their code for the programming assignments.

1 Like

Please post a screen capture image that shows the error message or assert.

I agree with @saifkhanengr, you must run all of the cells starting from the top of the notebook, every time you open the notebook. This is where the assets are imported and the workspace is configured.

1 Like

What could be the problem?

Your compute_gradient() code doesn’t return the correct value for dj_dw.

1 Like

So, what can I do to make it right?

Did you click on the “Click for Hints” link directly below the cell for the “compute_gradient()” function?

1 Like

Yes, I used the hints. That part where the new variable dj_dw_i is assigned to dj_dw using +=, might give a clue . Something went wrong before then, I guess, I can’t seem to get what went wrong.

Good day. I have run all the cells. It no longer says name error. It’s stuck on the Assertion error. I don’t know what else to do to make it go rightly.

Tips for those who find this thread later.

  • Indentation is important in Python code. That’s how it creates blocks of code.
  • Division by m should only be done once in the compute_gradient() function.
1 Like