I’m having some trouble with the week 2 lab.
sigmoid
initialize_with_zeros
propogate
optimize
predict
are all working. All tests passed, expected output matched.
In particular, for “optimize” I’m getting this output (this is not the code I wrote, this is the output to the test for the code)
I’m now working on the function “model”. This is supposed to put it all together and not only run gradient descent (which optimize already did) but also do a train/test split and evaluate the predicted values on the training and test data.
As far as I can tell, the main difference in the gradient descent aspect is the number of iterations and the learning rate, which I do not get to choose myself. In both cases, for optimize which is working and for model which is not, gradient descent is run on a one layer neural network with a logistic activation function.
I have model implemented, but I’m puzzled by the error I’m getting. It says that my value for my cost function is wrong. The only place I’m using a cost function in my code is at the output from optimize (and I don’t know of another place I should be using it within the model function?). I don’t know the number of iterations used in the test pictured below of the model function, but the test of optimize used 100 iterations, so the issue is not likely to be that something is wrong with the way I’m accumulating dw or db in the derivative, or with mismatched dimensions in the matrices in the optimization algorithm. It is not surprising, I guess, that the value I obtain by both the optimization and the model algorithms are basically the same-- the .159 value, because the initial state of w and b is the same because they are set to zero, and because it is operating on the same population of X data. However, some difference should be expected, because rather than operating on all of X, it is operating on X_train within the model function, and that makes it a bit surprising that the two results for the cost in the optimize function and the model function are numerically identical to all digits. Presumably it is correct, then, that the cost should be something else in the model function.
I’ve double checked the other issues in the error pictured. going back up to optimize, w seems to be an array before it was put into the dictionary, and I can’t really see how it would be anything other than an array when it is taken back out of the dictionary.
I can see that costs has the correct type, length, and format by the output from the optimize function above. So it is probably a numerical value issue, as the error actually thrown says.
I can’t think of any way I should need to modify the cost function after optimization is done. At that point, what remains should be prediction.
Could the issue be the deep copy of w in the model function? Although a data structure is an object, a deep copy is more meaningful in the context of a data structure containing a data structure, or a custom object. When w is deep copied, does it update w within the dictionary? Or is it necessary to deep copy the dictionary instead?
Thanks,
Steven