Hi Learners and Mentors,
I have a strange behaviour in my Python Notebook. I got global var errors - and two of three tests solved. Could someone give me a hint… maybe I am blind and don’t see the tree in the woods.
Hi Learners and Mentors,
I have a strange behaviour in my Python Notebook. I got global var errors - and two of three tests solved. Could someone give me a hint… maybe I am blind and don’t see the tree in the woods.
that global variable comment in the AssertionError message might be a red herring.
take a close look at the parenthesis and operator precedence in your equation for s = (...) in the sigmoid function.
Right! They are just saying that is one thing to look for. The other thing that should be a pretty strong clue that something is wrong is that your output values are all > 1. But sigmoid produces values in the range (0,1), right? So how could that happen?
Try the following and watch what happens:
m = 5
x = 1 / 1 + m
y = 1 / (1 + m)
If you’re expecting x and y to have the same value, you’re in for a surprise!
The other more common version of this “order of operations” problem is this:
m = 5
x = 1 / 2 * m
y = 1 / (2 * m)
This is a very generalizable idea that @paulinpaloalto has shared. It’s always a good idea to test new code using inputs where you know what the output should be. For example, you know, or can easily find out, that 0.5 = \sigma(0.0), 0.73 = \sigma(1.0) and 0.27 = \sigma(-1.0). What does your function produce? Then try extreme/boundary conditions. Always better to find bugs from using your own test harness than from the grader, or watching your orbiter crash on Mars because of a math error.
You can also understand more about how the tests work by clicking “File → Open” and then having a look at the file public_tests.py. If you’re new to python, it will be some work to understand, but you will find it illuminating. One point is that if you had 2 tests that passed, it is not necessarily a cause for celebration. Usually they test each output for three different attributes, in this order:
The type of the value
The shape of the value (if it is expected to be an array)
The actual values
So you passed the first two, because your output was a 1 x 3 vector containing floating point values. As mentioned above, that should not be something to make you feel a sense of pride and reassurance. Or to put it in more colloquial terms: a lot of their tests have a pretty low bar for success.
Thx - I really didn’t saw it. Silly mistake …thanks and happy learning!