Course 1, Week 2, Exercise 5

Hey there
I found already some other topics about this Exercise, but none seems to fit my problem: In my opinion i have implemented the right functions. But i do get error messages that the results do not match. Could you please point me out, what i oversee? (I post this as well because i have read there were some issues with the test)


AssertionError Traceback (most recent call last)
in
14 print ("cost = " + str(cost))
15
β€”> 16 propagate_test(propagate)

~/work/release/W2A2/public_tests.py in propagate_test(target)
39 assert type(grads[β€˜dw’]) == np.ndarray, f"Wrong type for grads[β€˜dw’]. {type(grads[β€˜dw’])} != np.ndarray"
40 assert grads[β€˜dw’].shape == w.shape, f"Wrong shape for grads[β€˜dw’]. {grads[β€˜dw’].shape} != {w.shape}"
β€”> 41 assert np.allclose(grads[β€˜dw’], expected_dw), f"Wrong values for grads[β€˜dw’]. {grads[β€˜dw’]} != {expected_dw}"
42 assert np.allclose(grads[β€˜db’], expected_db), f"Wrong values for grads[β€˜db’]. {grads[β€˜db’]} != {expected_db}"
43 assert np.allclose(cost, expected_cost), f"Wrong values for cost. {cost} != {expected_cost}"

AssertionError: Wrong values for grads[β€˜dw’]. [[-0.00942637]
[ 0.22120096]
[-0.89922014]] != [[-0.03909333]
[ 0.12501464]
[-0.99960809]]

Many thanks in advance for any help!

Best Michael

It was a problem with the calculation of the activation matrix. I never checked this one before and just found out, that i had some issue there. Maybe this helps others as well…

I experienced a similar issue as @Michael_Lappert but the error I received was β€œWrong values for cost” function. I have tried computing the loss using different ways over the past couple of days now but unfortunately, I still keep getting this same error. Please can any one help :pray:

Hello Rizama,

Are you sure that you are applying the correct formula into the equations?

Forward Propagation:

You get X
You compute  𝐴=𝜎(𝑀𝑇𝑋+𝑏)=(π‘Ž(1),π‘Ž(2),...,π‘Ž(π‘šβˆ’1),π‘Ž(π‘š)) 
You calculate the cost function:  𝐽=βˆ’1π‘šβˆ‘π‘šπ‘–=1(𝑦(𝑖)log(π‘Ž(𝑖))+(1βˆ’π‘¦(𝑖))log(1βˆ’π‘Ž(𝑖))) 
Here are the two formulas you will be using:

βˆ‚π½βˆ‚π‘€=1π‘šπ‘‹(π΄βˆ’π‘Œ)𝑇(7)
βˆ‚π½βˆ‚π‘=1π‘šβˆ‘π‘–=1π‘š(π‘Ž(𝑖)βˆ’π‘¦(𝑖))(8)
1 Like

Yes, that was the issue. The cost function formula was correct just that I transposed the wrong matrices. I already fixed it. Thanks for the assistance

Good to know that Rizama!

Keep learning!

Hi there @Rashmi could you assist I’m getting an error
C1 W2 Logistic Regression Excercise 4
AssertionError Traceback (most recent call last)
in
2 w, b = initialize_with_zeros(dim)
3
----> 4 assert type(b) == float
5 print ("w = " + str(w))
6 print ("b = " + str(b))

AssertionError:

If this is your first encounter with the β€œassert” statement in python, it is checking for a condition that is supposed to evaluate to True (boolean) and it fails or β€œthrows” if it is not true. So what is the condition that is failing in your case? It is shown by the statement:

So your b value is supposed to be a python float, but it isn’t. So how did that happen? You probably assigned b with the value 0, but that is an integer value in python. Note that 0 and 0. are not the same thing in python. That decimal point makes the value a floating point number.