Week2assignment-predict

Hi
In the model_test(model) code for assignment I have an error, but I don’t how to edit this. Could you explain it plz? Thanks

AssertionError Traceback (most recent call last)
in
----> 1 model_test(model)

~/work/release/W2A2/public_tests.py in model_test(target)
117 assert type(d[‘w’]) == np.ndarray, f"Wrong type for d[‘w’]. {type(d[‘w’])} != np.ndarray"
118 assert d[‘w’].shape == (X.shape[0], 1), f"Wrong shape for d[‘w’]. {d[‘w’].shape} != {(X.shape[0], 1)}"
→ 119 assert np.allclose(d[‘w’], expected_output[‘w’]), f"Wrong values for d[‘w’]. {d[‘w’]} != {expected_output[‘w’]}"
120
121 assert np.allclose(d[‘b’], expected_output[‘b’]), f"Wrong values for d[‘b’]. {d[‘b’]} != {expected_output[‘b’]}"

AssertionError: Wrong values for d[‘w’]. [[ 0.28154433]
[-0.11519574]
[ 0.13142694]
[ 0.20526551]] != [[ 0.00194946]
[-0.0005046 ]
[ 0.00083111]
[ 0.00143207]]

The problem is not in the test cell: the problem is that your actual code is wrong. You need to debug your code. That particular set of incorrect values for w probably means that you hard-wired some parameters on the call from model to optimize.

I am having the same issue I tried to debug the code but I am able to understand. first I had hard-wired some parameters but then I changed them. number of iterations are 100 and learning rate = 0.00005, Then I am getting this error!!

AssertionError Traceback (most recent call last)
in
----> 1 model_test(model)

~/work/release/W2A2/public_tests.py in model_test(target)
119 assert np.allclose(d[‘w’], expected_output[‘w’]), f"Wrong values for d[‘w’]. {d[‘w’]} != {expected_output[‘w’]}"
120
→ 121 assert np.allclose(d[‘b’], expected_output[‘b’]), f"Wrong values for d[‘b’]. {d[‘b’]} != {expected_output[‘b’]}"
122
123 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[‘b’]. 0.0008311670001839005 != 0.000831188

I found the solution but thanks anyways!!

Hi,
I had the same issue. So, is it always the rule that we don’t hard-wire the parameters when we call a function? For example, model(…, num_iterations=2000,…).

Thank you,
Nay

Right! You only specify the values at the top level, whatever that is. Of course these parameters are optional, so in some cases the default values at the lower level will be applied. But you normally only specify the hard-coded value like that in the function definition, where it has the effect of declaring the default value. Defining (declaring) a function is a whole different thing than invoking (calling) a function, right?

Yes. Thank you so much. That clarifies it!

I have the same errors, I tried the use the same values of num_iterations, learning_rate, print_cost, as in the optimize function but nothing changed.
I still have the error. Is that the way you corrected yours or what could I be doing wrong?

The point is that you should not “hard-code” any parameters inside the body of the model function. In particular, when you call optimize from model, there should not be any “=” equal signs in the parameter list you are passing down to optimize.

It works now. Thanks a lot