dj_db returns an incorrect number ( dj_db is wrong: -4.89 != -2)
I’ve used the hint and I still seem to be missing something
Yes, it seems your code does not work correctly.
Can you review my code?
Please post your full error (not code).
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 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"
64
AssertionError: Case 1: dj_db is wrong: -4.890625 != -2
(Sorry i dont know how to screen shot on windows)
Maybe you are dividing the dj_db by m within a loop. Have you checked more hints given to you?
Here is the hint:
### START CODE HERE ###
# Loop over examples
for i in range(m):
# Your code here to get prediction f_wb for the ith example
f_wb =
# Your code here to get the gradient for w from the ith example
dj_dw_i =
# Your code here to get the gradient for b from the ith example
dj_db_i =
# Update dj_db : In Python, a += 1 is the same as a = a + 1
dj_db += dj_db_i
# Update dj_dw
dj_dw += dj_dw_i
# Divide both dj_dw and dj_db by m
dj_dw = dj_dw / m
dj_db = dj_db / m
### END CODE HERE ###
Best,
Saif.
I’ve even used the hints. Instead of -4.89 im now getting -10 != -2
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 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"
64
AssertionError: Case 1: dj_db is wrong: -10.0 != -2
You must be making some mistakes in your code. Click my name and send me your code in a private message so I can check it.
You have changed the order of return
. It should be dj_dw, dj_db
, not dj_db, dj_dw
You just need to write the code between two lines, as below:
### START CODE HERE ###
### END CODE HERE ###`
Don’t need to change anything else.
You’re so clutch. Thank you so much
I just had the EXACT same problem - deleted all my code, pasted the hint and now it is working… apparently some syntax that somehow mixed it up? Any ideas on how to avoid that in the future?
Just a little bit of practice and some basic knowledge of Python.