W2_Ex-8_Reshaping array_model_test(model)

I can’t figure out how to get past this error with my prediction test. Help would be appreciated.

Hi @Stef_G,

For one, you are using hardcoded values and global variables in the assignment. Using hardcoded values and global variables might pass the tests in the assignment, but it will fail the autograder tests.

For example, instead of using 2, use X_train.shape[0]. With that being said, your implementation of w, b is incorrect, as you are using hard coded values.

Moreover, your implementation of params, grads, costs is also incorrect. In there, you are making 2 mistakes with the optimise function

  1. You are passing the original X and Y. If you look at the model function skeleton, there is no X and Y variables. Basically, by doing this, you are passing in global variables, also something you shouldn’t be doing. You should use the actual model function’s parameters instead of X and Y.
  2. When you are passing in the values to be used in the optimise function you are setting up new values for num_iterations and learning_rate. Please don’t change these values, instead use the default values as set up in the parameters of the model function.

Fix this and your function will run.

Also note, in case you have used global variables and hardcoded values in other graded functions of the assignment, change those as well. As I mentioned, you might pass the assignment tests, but you will fail the grader tests.

Best,
Mubsi

1 Like

Thanks @Mubsi , that got it running.

It just gives me the wrong value for w now:
image
What else am I missing?

Hi @Stef_G,

Okay here goes, I hope I explain this right:

Say I have an add function

def add(x, y=5):
return x + y

There are two ways I can use this function:

I can pass both values for x and y

add(x=4, y=7) or add(4, 7) # both are the same
11 # this is what the function will return me

The second way:

add(x=8) or add(8) # both are the same
13 # this is what the function will return me

In the first approach, even though there’s a default value for y (which is 5), I’m passing in values for both x and y, so when I pass a value of y, this new value replaces the default value for y.

In the second approach, I’m only passing a value for x, and not for y, so the default value for y is being used.

With this being said, so what I meant by this is:

(Only mentioning num_iterations for simplicity), so the function parameter with the default value is num_iterations=2000. Earlier, you made it num_iterations=200, so what this did was it gave num_iterations another default value of 200.

As I mentioned earlier, you shouldn’t hardcode this value, because the unit test which in this case is the hidden function model_test(model), uses a very different value of num_iterations.

The unit test uses a value of 50 for num_iterations. When you set it to num_iterations=200, it runs for 200 times, but the unit test expects it to run 50 times.

Now, when you have omit the mention of num_iterations, learning_rate and print_cost from your optimize function, they are using the default values set by the original function definition of model, which are 2000, 0.5 and False respectively. But the unit tests expects to pass in different values for these variables which is why you are failing the test.

So what you need to be doing is, mention these variables in the optimise function, but don’t assign any default or hardcoded values to them, and your function will pass.

Did I make sense ?

Mubsi

1 Like

HI I’m dealing with the same problrm and the abobe solutiom doesn’t work for me.
I will be happy for yor help

Hello @reut.oelboum.43!

Kindly share your full error with us.

Best,
Saif.

Hello,Reut.

Did you manage to sort out the error, you were facing? Please let us know. Thanks.

Hi i am facing the same issue and the solution doesn’t make sense to me.

Make sure you are using initialize_with_zeros function to initialize parameters with zeros.