Week 2 practice lab: Linear Regression - Exercise 2

Hello! Can someone help me please, I’m struggling to find the problem in my coding for exercise 2. After I run the first cell, this is the error it shows me:

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

AssertionError Traceback (most recent call last)
in
6 print(‘Gradient at initial w, b (zeros):’, tmp_dj_dw, tmp_dj_db)
7
----> 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 2: 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"
64

AssertionError: Case 2: dj_db is wrong: 0.0 != -2

The second cell at least runs the code, although the output isn’t as expected… :smiling_face_with_tear:

Note that your returned dj_db value is zero. That’s also the value that it was initialized to at the start of the compute_gradient() function.

So, your code isn’t updating the dj_db value.

Maybe your code is using an incorrect variable name. That’s just one possibility.

Hey, sorry for the late reply.
I reran all the cells again and it worked. I dont know why that happens.

Thank you still.

1 Like

Re-running all of the cells will re-create your workspace, and clear out any stale global variables.