Hi I have a similar issue. All previous code blocks have passed their tests, implying the error is in the def model block in Exercise 8, where 4 sections of code are required i.e.
#(≈ 1 line of code)
# initialize parameters with zeros
# and use the "shape" function to get the first dimension of X_train
# w, b = ...
#(≈ 1 line of code)
# Gradient descent
# params, grads, costs = ...
# Retrieve parameters w and b from dictionary "params"
# w = ...
# b = ...
# Predict test/train set examples (≈ 2 lines of code)
# Y_prediction_test = ...
# Y_prediction_train = ...
Am I allowed to post my code? Not clear on what breaches the honor system. I think the error may stem from where I set w and b (section beginning # Retrieve parameters); I have set them as their values in the “params” dictionary. The assert error then says my value of w is different to the expected value of w. Here is the error output:
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']}"
135 assert np.allclose(d['b'], expected_output['b']), f"Wrong values for d['b']. {d['b']} != {expected_output['b']}"
137 assert type(d['Y_prediction_test']) == np.ndarray, f"Wrong type for d['Y_prediction_test']. {type(d['Y_prediction_test'])} != np.ndarray"
AssertionError: Wrong values for d['w']. [[ 0.14449502]
[-0.1429235 ]
[-0.19867517]
[ 0.21265053]] != [[ 0.08639757]
[-0.08231268]
[-0.11798927]
[ 0.12866053]]
The assignment still submits with a score of 83, I’d like to understand the error though to get 100.
Thanks, I already did that (1st section: initialize_with_zeros(length of 1st dimension of X_train)). Then (2nd section) I called the optimize function to gain params, grads, costs. So in the 3rd section I have simply set w and b as e.g. z = params[“z”] where z is a general variable. That assert error then implies either that this is wrong or that my optimize function is wrong, but the code block for optimize (Exercise 6) is passing. Any ideas?
Fixed. I had copied and pasted the optimize call from Exercise 6, unfortunately this overrode the larger num_iterations and learning_rate inputs in Exercise 8, so w had the right shape but had not converged sufficently. Now all the code works.