Course 1 - week 2 assignment AssertionError: Wrong length for d['costs']. 20 != 1

I am getting error in the function model_test(model). For all the functions, I have got all tests passed.

When I execute this above method, I am getting
AssertionError: Wrong length for d[‘costs’]. 20 != 1

I am not able to sort out this issue, any idea or help where I may have made mistakes ?

1 Like

That error usually means that you are “hard-coding” the number of iterations and perhaps other parameters someplace. You’ve done 2000 iterations which is why you get 20 cost values, but the test case is asking for a smaller number of iterations. So how could that happen? Typically this happens when you call optimize from model: there should be no equal signs in any of the parameters being passed to that function, because that means you are ignoring the parameters being passed in at the top level to the model function. Another way to “hard-code” parameters is not to pass the learning rate, number of iterations and print flag on the call to optimize from model, since that would mean you will use the default values of those parameters which were declared in the definition of the optimize function. In other words, you’d be ignoring the actual requested values and using the defaults, which is another form of “hard-coding”. Although note that the default for number of iterations declared in the definition of optimize is 100, so that’s probably not the specific bug you have in this case.

11 Likes

Yes, you are right. Thanks. Now it is resolved.,

I had the same issue and your solution worked!

Thanks a lot, and my problem has been resolved.

Thanks. I had a similar issue, and this resolved it.

Thanks. I encountered the same issue, but it has been resolved

Thanks a lot. I have been trapped by this problem for a while.

1 Like