Hello I am having trouble with the exercise 8.

Here is the error that I am getting. I wonder if the way I compute the activation function ‘A’ is wrong. But it worked fine in Exercise 5 so I do not understand why it is not working here. Any help would be appreciated. Thank you.

You should the shapes of the w.T and X matrices, the first matrix should have number of rows equal to the seconds matrices number of columns! Check this first lets see if that’s right!

1 Like

In your `propagate`

function, while defining cost, you transposed the logarithms of matrices `A`

and `1-A`

but it should be `A`

and `1-A`

.

For example, log(X.T) and log(X).T lead to different shapes.

*{Update: “*`np.log`

operates “elementwise”, so that means that whether you do the transpose before or after applying log shouldn’t make any difference”}. Thanks, Paul for highlighting this.

2 Likes

I also notice that, in your propagate function, you are not calling the `sigmoid`

but defining it from scratch. Well, it works fine but in your Ex. 3, you already defined the sigmoid and you can just use its name (sigmoid) to use it again. No need to do all the equation work again.

1 Like

It is your w value that is the wrong shape. So where is that shape determined? Hint: it is in the `model`

function, right?

Also note that is not your only mistake: when you call `optimize`

from `model`

, you are hard-coding the values of the number of iterations and the learning rate, which means that the actual values passed by the test case are being ignored. E.g. no matter what number of iterations are requested, your code will always run 100 iterations. That will not end well.

1 Like