Yesterday I posted the same question on Coursera Discussion. I got a suggestion that I can just restart the kernel. I tried but it still failed.
I passed all tests before getting to this part. And the report of this error is confusing for me. Can anyone tell me how to do the debug? Thank you!
The mistake is that the w value that you are passing down to propagate is wrong there: it is 2 x 3, but it should be 4 x 1 so that w^T ends up being 1 x 4. So how did that happen? If all your other routines pass the test cases, then the bug must be in model. Print the size of w after the call to the initialize routine. If that is right, then your code is going off the rails in some other place. What is the shape in optimize?
I have the same problem having no idea what dimensions should I pass to initialize_with_zeros(dim) function. I tried with X_train.shape[0] but got IndexError: tuple index out of range. When trying with hardcoded values it failed too.
Any suggestions? @paulinpaloalto
I donât understand what do you mean by : âhow you specified thatâ. I am passing X_train.shape[0]
to i_w_z() function. The error I am getting is (the last part):
in predict(w, b, X)
14 âââ
15
â> 16 m = X.shape[1]
17 Y_prediction = np.zeros((1, m))
18 w = w.reshape(X.shape[0], 1)
IndexError: tuple index out of range
But prediction function, and all the others passed tests and gave correct outputs.
Regards, Andrzej.
It should be a numpy array and the shape should be a 2 tuple, but what do you actually see?
In other words, the bug is not in predict: the bug is that you are passing incorrect arguments when you call that from model. At least thatâs the theory ⌠Letâs see what the evidence shows.
but after run predict_test(predict) it changes to
type(X) = <class ânumpy.ndarrayâ>
X.shape = (3, 3)
I donât want to feel fired with thinking by your help so I need a bit more time to rethink this problem. Perhaps there is something wrong with clause I put to zero the w variable because I see later in the code (before computing hypothesis A), that w is reshaped with .reshape(X.shape[0],1). Truly saying I donât know in 100% why. Before it the shape of w is ((2,1), after that it is (3,1). Is that correct?
Yes, those are the correct shapes of w to match the X shapes that you show.
But the question is what you see when you call predict from model, right? The problem is not in predict: it is that there is something wrong with the parameters you are passing from model to predict.
It is a general principle of debugging that a perfectly correct function can still throw errors if you pass it bad parameters. So you start from the point of the error and then you have to work backwards to figure out where the problem really is. It may be higher up the call stack âŚ
Note that predict does not change any of its input values, right? So if there is something wrong with X, that is not the fault of the code in predict.
And it wasnât.
Is was as silly typo as the misunderstanding with bias variable. I put Y in place of X as a parameter to predict()
Thank You very much!
Although now that I think epsilon more about it, I donât understand why passing Y would cause the particular error about âindex out of rangeâ. Y is also a 2D array, right? Just of dimensions 1 x m, instead of n_x x m.
But if you solved it, maybe thatâs good enough and we should just move on âŚ
Youâre right. Understanding such errors, the curiosity, is the thing that moves us up and forward.
But today I had a hard day and I am tired enough, maybe later weâll talk about it, ok?
Sure, no worries. Itâs fine to just let it go. Sorry, but when I get in âdebug modeâ the whole point is you need to exactly understand what the error says and then how to map that back to what weâve done wrong. Thatâs the skill we are developing here.
Hi Paul,
Today I have had a bit of time at work and made some calculations in a python console, step by step going from w initialized to zeros counting loss, A and cost by hand for simple array of X.
Until now I did not feel how it is possible to find the right values starting from zero :D. But when I got in one of outputs an array of [0.5 0.5 0.5] all is happened clear. Sigmoid rulez! Zeros have its value And the minus sign of the derivative shows the direction of the gradient.
My faults from yesterday ware caused by lack of time and by reading without the understanding. All the answers are either in comments to the code or near to it. One have only to read carefully.
Cheers, Andrzej.
Thanks for your description of your thought process! Yes, it is a valuable lesson that the instructions in the notebooks are generally very thorough and clear. Itâs always worth reading them carefully. Sometimes it almost feels like they go too far and it ends up seeming like âtaking dictationâ as opposed to real programming.
Thereâs plenty more interesting material to come. Onward!