Hello,
Would you please help me to solve this error? All previous models works just fine. But once I tried to put them together. I know this is related to costs but I haven’t find any issue in code. Only what is suspicious is outcome of exercise 6.
Please find below full error message.

Thank you in advance

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)
127 assert type(d[‘costs’]) == list, f"Wrong type for d[‘costs’]. {type(d[‘costs’])} != list"
128 assert len(d[‘costs’]) == 1, f"Wrong length for d[‘costs’]. {len(d[‘costs’])} != 1"
→ 129 assert np.allclose(d[‘costs’], expected_output[‘costs’]), f"Wrong values for d[‘costs’]. {d[‘costs’]} != {expected_output[‘costs’]}"
130
131 assert type(d[‘w’]) == np.ndarray, f"Wrong type for d[‘w’]. {type(d[‘w’])} != np.ndarray"

AssertionError: Wrong values for d[‘costs’]. [array(0.68292667)] != [array(0.69314718)]

It problem could be hard coded values being passed to the optimize() function. Only name of argument should be passed to the function optimize(). Here is what it looks like:
optimize(w,b,X_train,Y_train,num_iterations,learning_rate)

I added a print statement to my optimize function to show the number of iterations and learning rate. Here’s what I see when I run the test cell for optimize:

optimize with num_iterations 100 learning_rate 0.009
w = [[0.80956046]
[2.0508202 ]]
b = 1.5948713189708588
dw = [[ 0.17860505]
[-0.04840656]]
db = -0.08888460336847771
Costs = [array(0.15900538)]
optimize with num_iterations 101 learning_rate 0.1
All tests passed!

Those values exactly agree with what you show for Exercise 6, so your optimize logic looks correct. So that means the problem is (as Kic says) with how you are calling optimize from model.

Here is my output from the model test case (also with some more added print statements):

model with num_iterations 50 learning_rate 0.01
before optimize w.shape (4, 1)
optimize with num_iterations 50 learning_rate 0.01
in model before predict call w.shape (4, 1)
predictions = [[1. 1. 0. 1. 0. 0. 1.]]
predictions = [[1. 1. 0.]]
costs = [array(0.69314718)]
All tests passed!

So this means that your costs value is wrong, but the costs value is returned from optimize, which is correct. The other point here is that there is only one element in the costs array, which means that it is the cost value after iteration 0, which means that no gradient updates have happened yet at the time that value is generated. So the learning rate and number of iterations haven’t had any effect on that value. Are you doing the “initialize” differently? E.g. not calling initialize_with_zeros? Or not passing the correct w and b values to optimize?