# C2W3 Final Assignment missing 5 points

Hello,

I completed course 2, but I’m having issues to understand what was the case for missing 5 points on the exercise 7:nn_model.

I’m getting 15/20. I’m not sure how to debug and find out how to score 20/20 on this part. When doing the exercise, the output says:

all tests passed

But when submitting for grading, the total is 95%, and for exercise 7, it outputs the log checks below:

``````Failed test case: "extra_check". Wrong weights matrix W1..
Expected:
[[-0.05350702 -0.10250995]
[-0.07303197 -0.1295294 ]
[-0.07487082 -0.11145172]],
but got:
[[-0.88792757 -2.15678679]
[-0.90083658 -2.29294507]
[-0.90485966 -2.2175348 ]].

Failed test case: "extra_check". Wrong bias vector b1..
Expected:
[[0.03448384]
[0.03609865]
[0.0347455 ]],
but got:
[[0.79242606]
[0.92205182]
[0.85903016]].

Failed test case: "extra_check". Wrong weights matrix W2..
Expected:
[[-0.39306094 -0.41154116 -0.40031599]],
but got:
[[-2.53898163 -2.75359949 -2.64586636]].

Failed test case: "extra_check". Wrong bias vector b2..
Expected:
[[-0.74585916]],
but got:
[[1.72524631]].
``````

Thanks!

1 Like

passing a unit test, whether here in the deeplearning programming exercises or IRL, means just that; passed a unit test. It doesn’t mean the code would pass some other unit test, and it doesn’t mean that the code is correct. Consider…

``````k = 6  #GLOBAL VARIABLE.

def my_sum(i, j):
return k

assert(6 ==my_sum(3,3))
print("Congrats!  Your code passed the first of three unit tests.")

assert(6==my_sum(5,1))
print("Yay! Your code passed the second of three unit tests.")

assert(9==my_sum(2,7))
print("Awesome! Your code passed the last of the unit tests.  It must be correct!")
``````
``````Congrats!  Your code passed the first of three unit tests.
Yay! Your code passed the second of three unit tests.

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Input In [4], in <cell line: 11>()
8 assert(6==my_sum(5,1))
9 print("Yay! Your code passed the second of three unit tests.")
---> 11 assert(9==my_sum(2,7))
12 print("Awesome! Your code passed the last of the unit tests.  It must be correct!")

AssertionError:
``````

Oops. So, what’s the takeaway? When your code passes the unit tests here, but fails the grader, look for hard coded values and/or the use of globals. The grader uses the Python `exec()` function to load and execute your graded code block, but it does so in its own context. You can’t count on variables that were at the global scope in your notebook to be available, and if they are, you can’t assume they will have the same values as in your notebook. The grader in fact deliberately uses different values for parameters to test whether you made this common mistake.

Hope it helps here and later in your programming career. Cheers.

ps: if you haven’t done, maybe spend some time with this book==>

which goes deeply into experiment and evidence and what proof means (or doesn’t mean).

1 Like

Thank you! I’m aware about what a unit test is. Also, that the code was incorrect since it covered only the first batch of simple assertions.

I was actually wondering about how to find the reason of my own mistake(s). Turns out the cause was due a simple syntax error. The discrepancy between the checked and expected weights was due the learning rate. I accidentally left it out when typing the main loop on exercise 7… Feel bad that this was the case (LOL) since the whole notebook is nicely explained (and commented)

Thanks again!

Glad you got it. Since it’s working and you figured it out on your own, what follows is for anyone else reading this thread in the future.

To be precise, the OP issue cannot have been a syntax error. Syntax errors cause the Python parser to stop. Doesn’t even go on to execute. If the code ran to completion, produced expected results in some cases but not in others, it had to be a programming logic error. And if learning rate was a parameter at one level that wasn’t passed though, then it is a subtle version of the prohibition against hard coding, since execution relied on the library default value. For test cases using the default value, it worked. For test cases not using the default value, it didn’t. When your code runs to completion and passes unit tests (in the notebook) but fails the grader or when running in a different execution context, look for places where context has leaked, like use of global variables or hard coded or parameter default values instead of passed parameters. HTH

1 Like

Thank you jaspier, for this topic.
Coz it would have taken me ages to find this if not you.
Cheers!

1 Like