Logistic Regression with A Neural Network Mindset

Logistic Regression with a Neural Network Mindset
Hi, I’m not sure why this function isn’t working, every time I try and set db or dw as anything I get a syntax error. See attached images. Thank you!

Welcome to the DL Specialization @James-P. Your first assignment is to review the Coursera Code of Conduct which forbids you to share your work in any public forum or with other learners. Please edit this post to remove the graded function. You are only allowed to share your output. Also, please identify the Week and the Exercise Number in your topic along with a short blurb regarding the issue. This allows other learners with similar issues to reference your post. Also, it is helpful to do a search yourself for similar posts.

First off, I see that you are throwing a NameError for ‘np’. You have not run the cell in the notebook that includes the import statements. The NumPy module is an absolute must. :slight_smile: You also have a simple syntax error. These often arise because you have an incomplete command in the line directly preceding (e.g. a dropped parenthesis). Also, watch out for extraneous spaces in your commands.

Hello, for the cost function on week 2 my current output is
dw = [[12.8 ]
db = 4.533333333333333
cost = nan

AssertionError Traceback (most recent call last)
14 print ("cost = " + str(cost))
—> 16 propagate_test(propagate)

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

AssertionError: Wrong values for grads[‘dw’]. [[12.8 ]
[30.82666667]] != [[0.99845601]

Why do you think the cost function isn’t returning a number? Thanks

Hi @James-P, I don’t know why it is not returning a cost but most probably it is linked with the fact that you are not correctly calculating w. So I would first focus on getting w right and most probably you will get naturally the cost right too :slight_smile:

Thank you, I’ve got it now. Cheers for your time