Week 2: Exercise 8

I am having the following error with model function at excersice 8 - model:

AssertionError: Wrong values for d[‘w’]. [[0.]
[0.]] != [[ 0.00194946]
[-0.0005046 ]
[ 0.00083111]
[ 0.00143207]]

What’s wrong?

1 Like

You are not passing through all the parameters for optimize, so the learning rate and number of iterations end up taking their default values as declared in the definition of the optimize function. That will cause your results to be different unless the parameters passed into model happen to agree with the default values.

Also please note that we are not supposed to post solution code in any public places including here on Discourse. Would you please do us a favor and edit your post to remove the code now that the question has been answered.

Hey @paulinpaloalto, from which course is this query from ?

@Mubsi: This is from C1 W2 A2: the Logistic Regression Assignment.

1 Like

Hi, I am getting a similar issue on exercise 8. My weight is not initializing with respect to the dimensions of X_train.shape[0] !!!

Getting the error:
ValueError: shapes (1,12288) and (2,3) not aligned: 12288 (dim 1) != 2 (dim 0)

Most likely that means you are referencing global variables like X inside your model function instead of the parameters that were passed in. As a result, they don’t match in shape.

1 Like

I do not really understand. I have already submitted the assignment, could you point me out where I am wrong in the code that I have generated?

Please realize that no-one else can see your notebooks, so we cannot reach in and just give you the answer. Would you please show us the whole exception trace you are getting? Does the grader accept your model function?

I have passed all the previous grader tests. But the model function is getting the error bellow

Note that when you call optimize from model, you are referencing the global variables X and Y, not the parameters that were passed into model. That is why the dimensions don’t match. Notice that you (correctly) reference X_train when you call initialize_with_zeros.

1 Like

Hi, I have a problem week2 “wrong shape for d[‘w’] at the model

That is probably the same type of problem that @pyaj and I are discussing. Please check for consistency in not referencing global variables. The approach is to print the shapes and see which one is wrong. How did it get that way?

It’s ok. Thanks. I thought that the suite should work without problems but it is not the case

It looks like you must have used X_train to compute Y_prediction_test, right? How else could that end up having the shape 1 x 209?

1 Like

Since this is a recurrent issue, could we send you our jupyter notebook by email so that you could debug the code for us? and show us our mistakes. Because I have tried tracking down the shape of w from other functions and I did not find a solution.

How to reference the parameters that were passed into the model function ?

Hi @pyaj, unfortunately we cannot debug the issues in your notebook, it wouldn’t help because we already know how to solve the issue :slight_smile: Debugging errors and wrong results is a significant part of machine learning practice and programming in general, learning how to do that it is part of the learning.

@paulinpaloalto has pointed you in the right direction, have a look a the model function definition:

def model(X_train, Y_train, X_test, Y_test, num_iterations=2000, learning_rate=0.5, print_cost=False):

As you can see X and Y used in your code are not part of the definition of the model function therefore you should not used them when calling optimize. Looking at the input parameters to model function think what should you used instead? Check what you used when initializing w and b


Thank you @albertovilla and @paulinpaloalto. I finally understood the problem and your guidance towards the solution!