Hello everyone,
It’s my first post on this DeepLearning.AI platform.
I am completing the C1_W2 lab. The Code Cell UNQ_C1 is correct but not the UNQ_C2.
Here is the message :
Code Cell UNQ_C2: Function ‘compute_gradient’ is incorrect. Check implementation. I
In the code, the error message is the following NameError Traceback (most recent call last)
in
46 for i in range(m):
47 # Your code here to get prediction f_wb for the ith example
—> 48 f_wb = w * x[i] + b
49
50 # Your code here to get the gradient for w from the ith example
NameError: name ‘x’ is not defined
Would someone be so kind as to look into my code for help please ? I do not manage to define x correctly.
Thank you for your reply.
However, I still do not see where and what the mistake is precisely. May I send you my code so you could have a closer look ?
The ‘x’ variable is passed to the gradient_descent() function. You do not need to define it inside the function.
And the first few cells in the notebook are where the packages are imported and the data set is created.
Every time you open the notebook, you must run all of the cells starting from the top.
Also, please do not post your code on the forum. That breaks the Code of Conduct. If a mentor needs to see your code, we’ll contact you with instructions.
Note that when @Girijesh, said “personally send me your code”, the meaning was that you should click on his user ID and use the “Message” button. That sends a private message, so your code isn’t shared on the forum.
Your issue is caused by an indentation problem here:
for i in range(m):
h = h + 2*i
Python creates executable blocks of code based on indentation. Everything after the def gradient_descent(...):
statement must be indented, all the way to the return statement.