Evaluating a Model with PyTorch
Introduction
Hello! In today's lesson, we will be diving into evaluating models in PyTorch. Evaluating the performance of a model plays a key role in the process of building an effective machine learning model. It helps us to understand the ability of the model to generalize on unseen data. We will attain this by using a test dataset, making predictions using our trained model, and comparing these predictions with the actual truth values in the test dataset.
Recap: Training the Model
Before evaluating the model, let's quickly recap the training process:
Here’s a summary of the steps:
- Data Preparation: Defined training features
X_trainand targetsy_train. - Model Architecture: Created a network using
nn.Sequentialwith one hidden layer (ReLU) and an output layer (Sigmoid). - Loss and Optimizer: Used Binary Cross-Entropy Loss (
BCELoss) and the Adam optimizer. - Training Loop: Trained for 50 epochs, performing forward pass, loss calculation, backpropagation, and parameter updates in each epoch.
Now let's move to evaluating our model.
Loading and Preparing the Test Dataset
Before we evaluate our model, we need to prepare our test dataset. The test dataset consists of new data points that the model has never seen before. This helps us understand how well our model generalizes to unseen data.
Let's define our testing data with the same format our model was trained on in the previous lessons:
With our test data ready, we can now move on to evaluating our model's performance using these new examples.
