Week 2 - Exercise 8 (Model)

I passed all the tests until Exercise 8, but somehow I’m getting an error message in this exercise that is pointing to my earlier answers, in particular my cost implementation.

Can anyone please help me?

Your lower level functions are correct, but a perfectly correct function will do the wrong thing or even throw an error if you pass it incorrect parameters. In your case, you have called the initialization function with the number of samples (columns) of the input X matrix. That is why the dimension of w does not match when it comes time to do the dot product down in the bowels of the propagate function. So initialize_with_zeros and propagate are correct, but you called them with mismatching parameters because of a bug in your model function.


Thank you! I would never think to suspect that part!

I’m glad that it helped, but there is a larger point I was trying to make here: it is a general principle of debugging that just because the error is thrown in a particular function does not mean that is where the problem actually is. So the reasoning that I went through to get from the point of the error back to the place higher up the call stack where the problem actually is was the “meta” lesson I was hoping to convey there. Debugging is part of the job and you need to work on developing your skills in that area. You start with the error message: what does it mean? One of the objects w or X is the wrong shape in that dot product. Which one is wrong? Compare the shape of X and it’s the same as in the test case, so it’s w that is wrong. What shape should it be? It is 3 x 1, but it should be 4 x 1. Ok, where is the shape of w determined? Clearly not in propagate, right? In propagate w is simply an input and it is used “as is” and not changed. The shape is determined initially by the call to the initialize routine. It is also potentially modified by the “update parameters” logic in optimize. So those are the places you need to look to find the problem.

So the larger point is that next time you get an error, see if you can apply that type of thinking to solve the problem yourself. Once you finish these courses and try to apply these ideas to solve real world problems, you need to have the skills to debug the issues that you encounter. Who are you going to call when something doesn’t work the first time if you don’t have the forums?

1 Like

Thanks! That made me go through how the model runs more closely to reproduce your reasoning. Just one more question: How could you tell “Compare the shape of X and it’s the same as in the test case”? Where can I see the test data for this question?

You can see from either the code in the notebook or the exception trace that the function model_test is defined in the file public_tests.py. If you click “File → Open”, you will be able to open that file. There is a topic about that on the FAQ Thread.

Or you can just add a print statement early in the model function to see the shape of X_train.

1 Like