Hi,
I have passed all previous tests and try to run Ex7. But it shows one of my predictions is wrong and I don’t know where I could have made a mistake. Some help please?
Hi,
I have passed all previous tests and try to run Ex7. But it shows one of my predictions is wrong and I don’t know where I could have made a mistake. Some help please?
The predict function is “self-contained”, so the fact that your previous functions are correct is irrelevant. You must have made some mistake in the internal logic of predict. You could instrument the code a bit to see the intermediate value of A. Here’s what I get when I do that:
A = [[0.52241976 0.50960677 0.34597965]]
predictions = [[1. 1. 0.]]
A = [[0.72445526 0.46920652 0.55395658]]
All tests passed!
Note that there are two separate test cases: one you can see in the notebook and another from public_tests.py.
Do you see the same A values? If so, then the problem must be in the logic that compares the A values to 0.5.
Hi Paul,
Thank you for your explaination. I printed out values of A and see exact same numbers as you have here. You said that it should be in the logic that compares A values to 0.5, but I am pretty confident about my 4 lines of code which is easy to write. So I don’t know where could be a glitch. Am I allowed to put the 4 lines of code on here?
What is your iteration count, i.,e range setting for “i” ?
Looks like your first answer is correct, but others are unknown. As all are initialized to zero, your logic may only touch the first element.
That just means you’re not looking hard enough at those 4 lines of code. To give a concrete example of what Nobu is talking about, one common mistake is to use 0 instead of i as the index when you assign values to the output prediction array. That would account for the fact that only the first element of the result is 1. Or perhaps you are not indexing the A value correctly. Note that both are 2 dimensional arrays of dimension 1 x m, right? Where m is the number of samples …
Of course the better way to implement this is not to use a loop at all. You can just do a direct Boolean comparison with an array and 0.5. You can write that logic as a single clear line of python if you do it that way.