When I calculate the cost function in this assignment:
def compute_cost(A2, Y):
“”"
Computes the cross-entropy cost given in equation (13)
Arguments:
A2 -- The sigmoid output of the second activation, of shape (1, number of examples)
Y -- "true" labels vector of shape (1, number of examples)
Returns:
cost -- cross-entropy cost given equation (13)
"""
m = Y.shape[1] # number of examples
# Compute the cross-entropy cost
# (≈ 2 lines of code)
# logprobs = ...
# cost = ...
# YOUR CODE STARTS HERE
# YOUR CODE ENDS HERE
cost = float(np.squeeze(cost)) # makes sure cost is the dimension we expect.
# E.g., turns [[17]] into 17
return cost
Further: This function works well for later usage. No any other functions failed or test failed, so I think it is not a big deal, but due to some calculation errors.
Hello @graceyang, and welcome to the DL Specialization. Before we start you need to delete the box that contains your code. Please be mindful never to post any thing that you have entered to implement a function, i.e. anything between the # YOUR CODE STARTS HERE and # YOUR CODE ENDS HERE comments. Thanks!
@kenb Thanks to reply. I didn’t know how to delete part of my question. Does it mean that I can’t get suggestion if I can’t remove this part of codes? I tried, but don’t know how. So I only can post the result instead of my code?
@kenb Oh, I found the solution to remove my code. Now could you let me know why I got this error? I am still curious why my tests failed, but it works later.
Thanks, @graceyang. Can you post a snip of the cell output that identifies the sequence of errors? The is called the “traceback.” But you should still take care to not include any parts that reveal your code.
As I recall, you were having a problem with coding the expression for the cost function. You can start be making sure that you understand the mathematical function as presented in the notebook and then trying to express that understanding in the required Python code.
Hi @graceyang. I see that you did post the traceback. Apologies! It’s curious that your result is very close to the expected output. ← That’s me. Stay tuned!
~/work/release/W3A1/test_utils.py in single_test(test_cases, target)
119 print(’\033[92m’, success," Tests passed")
120 print(’\033[91m’, len(test_cases) - success, " Tests failed")
→ 121 raise AssertionError(“Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))
122
123 def multiple_test(test_cases, target):
AssertionError: Not all tests were passed for compute_cost. Check your equations and avoid using global variables inside the function.
I have the exact same screen results. Following exactly the suggestion in the comment above the cost function code. I’m just using the def function compute_cost line, which does reference the names of global parameters, but, of course, doesn’t default the values (which in code above created issues for the test function.
I have to ask how “graceyang” “solved the issue”. Is it possible the problem lies in the test function?
~/work/release/W3A1/test_utils.py in single_test(test_cases, target)
129 print(’\033[91m’, len(test_cases) - success, " Tests failed")
130 raise AssertionError(
→ 131 “Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))
132
133
AssertionError: Not all tests were passed for compute_cost. Check your equations and avoid using global variables inside the function.
Thanks!
update: i neglected to use complete formula for “logprobs”. It’s working now!