Week # must be added in the tags option of the post.
Link to the classroom item you are referring to:
Description (include relevant info but please do not post solution code or your entire notebook)
I am taking the week 2 Programming Assignment and I am stuck at Exercise 8 - model. I keep getting “AssertionError: Wrong values for d[‘w’]”. However, all previous Exercises work fine (all tests passed). Can someone please advise? Thank you.
Double-check the initialization of w and ensure that it gets updated correctly during training. Also, make sure to follow the code instructions exactly as provided in the assignment. Debug your code by printing the intermediate variables to find the issue faster.
Hope it helps! Feel free to ask if you need further assistance.
Dear @Alireza_Saei,
Thank you for getting back to me. I checked and w is initialised correctly afaik.
My assert error message actually refers to dw, not w. The strange thing is that the error message then reports my wrong values (see below, where I’ve added a print statement to check the w values during iteration), but these are w values, not dw values. I am confused… Could it be that something is wrong with the assert statement? Either way, I’d grateful for more advice.
w (after) [[ 0.14449502]
[-0.1429235 ]
[-0.19867517]
[ 0.21265053]]
b (after) -0.0759564065803776
AssertionError Traceback (most recent call last)
in
1 from public_tests import *
2
----> 3 model_test(model)
~/work/release/W2A2/public_tests.py in model_test(target)
131 assert type(d[‘w’]) == np.ndarray, f"Wrong type for d[‘w’]. {type(d[‘w’])} != np.ndarray"
132 assert d[‘w’].shape == (X.shape[0], 1), f"Wrong shape for d[‘w’]. {d[‘w’].shape} != {(X.shape[0], 1)}"
→ 133 assert np.allclose(d[‘w’], expected_output[‘w’]), f"Wrong values for d[‘w’]. {d[‘w’]} != {expected_output[‘w’]}"
134
135 assert np.allclose(d[‘b’], expected_output[‘b’]), f"Wrong values for d[‘b’]. {d[‘b’]} != {expected_output[‘b’]}"
The AssertionError message is saying your output does not match the expected output. Your output (left of the ‘!=’ sign) and the expected output (right of the ‘!=’ sign), and the ‘!=’ means not equal.
If you have extracted the correct dimensions and passed it to the initialization function correctly, then one more thing to check is the parameters passed to the optimize() function, making sure there is no hard-coded value.
Testing of this model() function is given a different set of data. If hard-coded value is used, then it would produce the wrong output.
Thank you for your comments. My point about the Assert statement is that it seems wrong in principle to expect ‘dw’ (a gradient step) to be equal to ‘w’ (a weight):
As far as I can see, there are no hard wired values. I don’t understand how I can pass all Exercises 1 - 7 but then fail Exercise 8 by getting the wrong dw values. Any more advice? I have passed the assignment but I would really like to get 100%.
As mentioned in my earlier reply, to check parameters passing to the function optimize().
In your code for the model() function, the parameter for number_iterations and learning_rate were not passed to optimize(), as such the default values set for the optimize() function as seen in the definition were used, hence your code produced a different set of results when ran under the public test which used a different learning_rate and number_iterations.
I’m glad to hear that you were able to find the problem with Kin’s advice. One other thing to mention for future reference is that you are misinterpreting that assert message. It is not talking about dw (the gradient of w) it is using d['w'], which is a python dictionary named d and they are extracting the element with a key of 'w' which is the value of w.