Train/test accuracy mismatch

Hello,

     I am doing the assignment for the week 2. After assembling all the functions for the final model and making the predictions,  I am getting a train and test accuracy of about 68% and 34% respectively. I was looking for errors in my code and was unable to spot any. There was also no output to the plot showing the learning curve. However, after submitting the assignment I was able to score 100%. Hope somebody can provide some suggestions. Thanks in advance.

It sounds like your code is correct, if the grader gives you 100%, but things can still go wrong if your input data is incorrect or if you have modified the parameters being used in the training. Please check to make sure that you have an assertion in the “reshape” section that looks like this and that it doesn’t “throw” when you run that cell:

# Check that the first 10 pixels of the second image are in the correct place
assert np.alltrue(train_set_x_flatten[0:10, 1] == [196, 192, 190, 193, 186, 182, 188, 179, 174, 213]), "Wrong solution. Use (X.shape[0], -1).T."

The other thing to check is to make sure you didn’t modify the cell that does the actual training. Here’s what that looks like in my notebook:

logistic_regression_model = model(train_set_x, train_set_y, test_set_x, test_set_y, num_iterations=2000, learning_rate=0.005, print_cost=True)

Make sure you didn’t change the number of iterations or the learning rate that is being used there. Please let us know if neither of the above issues accounts for the behavior you are seeing.

I am having the exact same issue as soumdtt. I can confirm that the logistic_regression_model is equal to what paulinpaloalto posted. I don’t see anything pop up from the assert statement either.

Also, @paulinpaloalto’s suggestion to check up on the training cell brings up the issue of the keyword arguments. With @soumdtt 's result of 68% train accuracy makes me believe that your model() function may not be inheriting the proper arguments as set forth in the test cell. I think that it is stopping early, i.e. not the right number of iterations (too small). When building a model from previously defined helper functions, it is tempting to blindly cut and paste. I suggest that you inspect the call to optimize() in model().

1 Like

Good points! The other thing that just happened recently is that the course staff has fixed some problems with the tests in the notebook: the tests were missing some errors. It’s worth updating to the new notebook and rerunning all the tests. To do this, just open the Logistic Regression notebook and you’ll get the new version. Then you need to use the procedure on the FAQ Thread to update the new notebook with your previously completed work.