# W2\_A2\_Ex-8\_Wrong Values for d\['costs'\]

**URL:** <https://community.deeplearning.ai/t/w2-a2-ex-8-wrong-values-for-d-costs/545306>\
**Category:** Neural Networks and Deep Learning\
**Tags:** week-module-2, coursera-platform\
**Created:** [January 15, 2024, 8:35pm UTC](https://community.deeplearning.ai/t/w2-a2-ex-8-wrong-values-for-d-costs/545306 "2024-01-15T20:35:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Otakar\_Zavada](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Otakar\_Zavada](https://community.deeplearning.ai/u/Otakar_Zavada)\
**Post date:** [January 15, 2024, 8:35pm UTC](https://community.deeplearning.ai/t/w2-a2-ex-8-wrong-values-for-d-costs/545306/1 "2024-01-15T20:35:58Z")

</div>

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.

 ![image](https://global.discourse-cdn.com/dlai/original/3X/8/0/80244508d2fb252c3d58e485299af12d5979ec7a.png)

## 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)]

---

<div class="post-metadata">

**Author:** ![Kic](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/kic/32/76339_2.png) [@Kic](https://community.deeplearning.ai/u/Kic)\
**Post date:** [January 15, 2024, 9:23pm UTC](https://community.deeplearning.ai/t/w2-a2-ex-8-wrong-values-for-d-costs/545306/2 "2024-01-15T21:23:45Z")

</div>

Hi @Otakar_Zavada ,

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)

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [January 16, 2024, 4:05am UTC](https://community.deeplearning.ai/t/w2-a2-ex-8-wrong-values-for-d-costs/545306/3 "2024-01-16T04:05:24Z")

</div>

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:

```auto
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):

```auto
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`?

---

<div class="post-metadata">

**Author:** ![Otakar\_Zavada](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Otakar\_Zavada](https://community.deeplearning.ai/u/Otakar_Zavada)\
**Post date:** [January 16, 2024, 12:06pm UTC](https://community.deeplearning.ai/t/w2-a2-ex-8-wrong-values-for-d-costs/545306/4 "2024-01-16T12:06:58Z")

</div>

Hello gents,

thank you for your input. You are right. I had typo in initiliaze\_with\_zeros. I fix it and rerun all modules and now it works just fine.

Thank a lot

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [January 16, 2024, 3:42pm UTC](https://community.deeplearning.ai/t/w2-a2-ex-8-wrong-values-for-d-costs/545306/5 "2024-01-16T15:42:34Z")

</div>

It’s great to hear that you were able to solve this just based on the hints that we suggested. Nice work!
