Week 2 Ex. 8 Calling predict on the test set before calling predict on the training set


I cannot figure out my error here; I think it’s perhaps to do with my initialization of w.

Secondly I would also like to enquire why we call predict on the test set before we do so on the training set in this Exercise. I would think that we have to train the model before we test it and surely that is only possible after comparing the predictions of the training set with the training labels?

Yeah that probably has to do with the w shape initialization, it practically gives you the shape its asking. The predict will always be used on test set, the trained set already has seen labels and fitted them, the predict doesnt make any sense on training data.

Thank you for your explanation. I fixed my problem and reread through the whole assignment. I think I understand exactly how it works now.

1 Like

It is fine to call predict on either the training data or the test data in either order. At the point in the code where they do that, the point is that the model has already been trained. So now the question is “how does it perform?” The difference between how it performs on the training set versus the test set is a pretty important metric to understand whether your training was successful or not. “Overfitting” or “underfitting” or …

Stay tuned to hear much more about all that from Prof Ng as you go through this course and Course 2 in this series.