Making Predictions with a Trained PyTorch Model
Introduction
Greetings! In today's lesson, we will learn how to use a trained PyTorch model to make predictions. In previous lessons, we've already learned how to define and train a neural network using the PyTorch library. Now, it's time to utilize our trained model and make it useful by producing predictions. To make the lesson as hands-on as possible, we'll be using a trained model to predict if a team is likely to win based on average goals scored by the team and average goals conceded by the opponent.
Brief Recap of Training
Before we dive into making predictions, let's briefly recap how to train a binary classification model. Here's the code snippet we will use for training:
Switching the Model to Evaluation Mode
The first crucial step after we've trained our model is to put it in evaluation mode using model.eval(). But why do we need to do that? Models can behave differently during training and evaluation phases. For example, many components or layers of the model may have certain behaviors that only need to occur during training, like adjusting internal parameters based on the provided data.
Putting the model in evaluation mode ensures that these components function correctly for making predictions.
Let's go ahead and put our model in evaluation mode:
Do keep in mind that once we finish predicting, if we want to do further training, we will need to set the model back to the training mode using model.train() before starting the training phase.
