Programming assigment: Logistic_Regression_with_a_Neural_Network_mindset

The exercise 8 has 2000 iterations and taking into account that we record the cost in the costs list every 100 iterations at the end we get a list of length 20. But the public test raises a error saying: ‘Wrong length for d[‘costs’]. 20 != 1’. How can the costs list have only one element?

Note that the model_test() function creates a unit test using 50 iterations. This overrides the default value of 2000 that is in the model() function definition.

But the problem is that your code in optimize() that returns the “costs” value is returning a vector of 20 elements, but instead it should be a scalar. That’s what the assert in model_test() is checking for.

If you are new to python, you should google “python named parameters” or “python keyword parameters” and read up on how those work. As Tom says, the fact that the definition of the model function contains num_iterations = 2000, that does not mean that we will do 2000 iterations every time the function is called. It only means that if the caller does not supply the number of iterations, then we will do 2000. But if the parameter is actually passed, then we do the number that is requested by the caller.

1 Like

Thanks to both of you for your very quick and useful answers. The problem was, as you pointed out, the wrong way the parameters were passed to the function ‘optimize’ within the function ‘model’: The parameters of the function ‘model’ were updated correctly by the model_test function but the parameters of the function 'optimize´ were not updated at all.

Kind regards
Miguel Doñate