Course 1 Week 2 Exercise 8

Hi All,

I am getting the following error when I run model_test, and I am not sure what the cause is. I’ve tried printing the shape of w and X at various point, but this hasn’t shed any light on it. Any help is appreciated. Thanks in advance.

Hi @mcgleeno I assume this is the excercise 8 of the notebook, can I ask you if all the precedent excercises checkspoints were succesful?

I’m having an issue with Exercise #8 also. All the preceding tests passed but I’m getting a dimension mismatch with, I think, the sigmoid function. Can’t tell what are the inputs to test so not sure how to debug.

2 Likes

I have a similar problem

All my previous exercises are passed

@jlbanaag the error is not in the sigmoid function but rather en the np.dot inside the function i.e. np.dot(w.T, X). The error is indicating that the dimensions of w.T and X don’t match for a proper dot operation.

In order to debug this issue you could print the content and the shape of both variables prior this statement so you could check what is failing.

Note that most probably the error is with w as X is an input.

@Kyle you could debug your issue in the same way, it seems there is a mismatch between w.T and X.

1 Like

Hi there. If you’re having trouble as described above go to the model procedure. Look at the dim value , do you see it defined anywhere within the scope of the proc?? …NO. Therefore from ( LEGB ) rule dim inherits its value from the environment , python people, should know this. Dim is actually equal to 2 so that’s why wT has the wrong dimension for the model test, so here is what you do.

dim=X_train.shape[0]
w, b = initialize_with_zeros(dim)

Its a bug in their logic.

7 Likes

Thanks, I found where the bug was in my code. Thanks.

Hi All,

I have the same problem as [mcgleeno] with Exercise #8. All exercises before done successfully.
Could you give me some ideas on how to debug it?
2db14128599f4b3ab6c0790c9b1f06ddbbd1668b_2_690x387

As the error is linked with the fact that w cannot be reshaped as indicated by that line of code I would try to:

  1. print the shape of w before the error occurs, e.g. before the call to predict, and
  2. I would also print w itself to see if it looks correct

If w is not correct then you should check when it is calculated / defined.

3 Likes

Also having trouble with Course 1 Week 2 Exercise 8
Getting the
ValueError: shapes (1, 209) and (2,3) not aligned: 209 (dime 1) != 2 (dime 0).
w.shape = (209, 1)
Initialize to zeros worked.
Do I need to make w.shape(1, 209)?
Was that supposed to have been done in another section?

{moderator edit - solution code removed}

Make sure you are using X_train and X_test correctly.

That was it. I just copied the call to optimize from the previous step without changing X to X_train, and Y to Y_train. It now runs but gives me an error that the values don’t match the test.

Thanks for the help!