Lightning AI Studios: Never set up a local environment again →

Log in or create a free Lightning.ai account to track your progress and access additional course materials  

3.6 Training a Logistic Regression Model in PyTorch – Parts 1-3

Code

What we covered in this video lecture

In this lecture, we put all the basic concepts into action:

  1. We implemented a logistic regression model using the torch.nn.Module class.
  2. We then trained the logistic regression module by implementing a training loop based on PyTorch’s automatic differentiation capabilities.

After completing this lecture, we now have all the essential tools for implementing deep neural networks in the next unit: activation functions, loss functions, and essential deep learning utilities of the PyTorch API.

But before we jump into the next unit, we will cover a small but critical concept that is essential for training neural networks well: input feature normalization.

Log in or create a free Lightning.ai account to access:

  • Quizzes
  • Completion badges
  • Progress tracking
  • Additional downloadable content
  • Additional AI education resources
  • Notifications when new units are released
  • Free cloud computing credits

Quiz: 3.6 Training a Logistic Regression Model in PyTorch - PART 1

Suppose we implement a logistic regression model as a binary classifier for a dataset with 4 features using a linear layer self.linear = torch.nn.Linear(a, b). What are the numeric values for a and b in this case?

Incorrect. We have 4 input features.

Incorrect. We have 4 input features.

Correct. We have 4 input features and 1 output value.

Incorrect. We have 4 input features.

Incorrect. We have 4 input features not output features.

Please answer all questions to proceed.

Quiz: 3.6 Training a Logistic Regression Model in PyTorch - PART 2

When we define a dataset in PyTorch using the Dataset class, we implement an __getitem__ method, which returns

Incorrect. Hint: What does the model need to make a prediction?

Incorrect. Hint: what do we need in order to compute the loss?

Incorrect. Hint: The weight update is computed based on the loss, and what else do we need for that?

Correct. It returns a single training example plus label. We use the training example to obtain the prediction and the label to compute the loss.

Please answer all questions to proceed.

Quiz: 3.6 Training a Logistic Regression Model in PyTorch - PART 3

Suppose we want to use the torch.where function to compute the class labels based on the predicted probability values, torch.where(probas > a, b, c). What are the correct values for a, b, c?

Incorrect. If the probas are values between 0 and 1, what should the threshold a be?

Correct. If the probas are greater than 0.5, we return label 1, and label 0 otherwise.

Incorrect. If the probas are values between 0 and 1, what should the threshold a be?

Incorrect. If the probas are values between 0 and 1, what should the threshold a be?

Incorrect. If the probas are greater than 0.5, we return label 1, and label 0 otherwise.

Incorrect. If the probas are values between 0 and 1, what should the threshold a be?

Please answer all questions to proceed.
Watch Video 1

Unit 3.6

Videos