Error in the pre written code week 3 practice assignment


Whats the error? Its pre written .

Hi @Aryavardhan_Singh_Ra ,

The error message is from the unit test, it is reporting that the value returned didn’t match the expected one. There is problem with your code for the function comput_cost_reg(). One way to debug is to use print statement to print out value that is important for the calculation, which would help trace where the problem may be. In python, the value nan represent something that is not defined. So how could that happen in your code?

A nuance may have been overlooked. While it is true that compute_cost_reg_test() is not your code, notice the argument being passed in. Here, compute_cost_reg is a Python object holding the code you did write. Later, inside the unit test code, your function becomes the local variable target, which is invoked, passing in the local variables x, y, w, b, and lambda_. See line 92 of the error trace.

NOTE: this is why you should never hardcode values in your code…the unit tests pass their own parameters, not the values you tested with yourself, and compute the expected value with those parameters. If you hardcode inside your function or use global variables instead of function parameters, you will not match the unit test expected output.

In this case, the output returned by your function did not ‘match’ the value in the assertion. Notice also that this unit test code would be more correct if the return from invoking your function was called computed_output or actual_output since we don’t know a priori whether the value returned is the expected_output or not (in this instance it is not)

I can tell that the problem is not one of hardcoding, however, without even looking at the implementation. Notice that there is another clue to a problem before the unit test is even run, which is the computed cost printed out is nan. You never want to see nan in deep learning. This tells me there is a problem with the mathematics in the compute_cost_reg() implementation. Hope this helps.