C1_W2_Linear_Regression - I'm stuck

I’m a bit lost trying to understand this error on In [20]

I have run all the cells above.

Where should I go about fixing this?

Gradient at initial w, b (zeros): -0.04747762052631062 -0.007323908939747608
Using X with shape (4, 1)

AssertionError Traceback (most recent call last)
6 print(‘Gradient at initial w, b (zeros):’, tmp_dj_dw, tmp_dj_db)
----> 8 compute_gradient_test(compute_gradient)

~/work/public_tests.py in compute_gradient_test(target)
60 dj_dw, dj_db = target(x, y, initial_w, initial_b)
61 #assert dj_dw.shape == initial_w.shape, f"Wrong shape for dj_dw. {dj_dw} != {initial_w.shape}"
—> 62 assert dj_db == -2, f"Case 1: dj_db is wrong: {dj_db} != -2"
63 assert np.allclose(dj_dw, -10.0), f"Case 1: dj_dw is wrong: {dj_dw} != -10.0"

AssertionError: Case 1: dj_db is wrong: -0.6640625 != -2

Previous to that, this is my code:

# UNQ_C2
# GRADED FUNCTION: compute_gradient
def compute_gradient(x, y, w, b):
# moderator edit: code removed
    return dj_dw, dj_db

Your codes are incorrect. Please refer this to do the correction

If still not understanding, let me know
Note: Please stop copy and pasting your code that is when you do most of the mistake, why have you written double times most of the code with = sign??

Your C2 Code cell looks like this and you have taken the hint part of the code and pasted in your grader cell and that is why you are stuck

Hints are only to help you get the right code which you apply accordingly and do not copy and paste as shown in the hint cells.


@estebillan, please do not post your code on the forum. Sharing your code is not allowed by the Code of Conduct.

I have edited your message to remove the code.

The error means that your code does not compute the correct value for dj_db.

I apologize, I was not aware.

OK sorry about that, I was doing this at 2am and made it worse trying to fix an earlier error…

I’ve fixed it now, indentation problem. Thanks!

Hi ,

I am getting below error while I am submitting the assignment 2 of Supervised Machine Learning: Regression and Classification course. Please let me know how I can resolve this issue.

error : Cell #3. Can’t compile the student’s code. Error: OSError(‘data/ex1data2.txt not found.’)

Hello Sagiraju,

Based on your error log, this post comment might help you understand why student codes error comes.

You might have basically not written code or incompletely written code for your grader exercise cell 1.

Although the link is from another assignment, but issue looks similar. Your cell 3 can’t compile code because your previous exercise cell is incomplete or have not been written with any code.

Please refer this post to have an understanding about student’s code error.

Otherwise, share a screenshot of your error log, to help you better.

Ideally if any issue which is different from post heading, it is better to create a new post by choosing the appropriate specialisation, course, week’s and assignment name with explanation of your issue encountered would be better approach to get faster reply from respective mentors.


Hi Everyone,
I’m still having difficulty in progressing in this course. Although I have attempted the 2 exercises, I have not been able to pass the second exercise on cost gradient (C1_W2_Linear_Regression). The code is not returning any error. I have made several attempt. Please assist

1 Like

@George_Adedoyin_Olaw, as you have not posted on this thread before, please post some screen capture images or give some additional information about your situation.


Looks like your code has two return statements. Why?

The variables you are using here are not correct.

dj_dw_i and dj_db_i.

(image removed)

Thanks @TMosh . resolved.