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  

4.5 Multilayer Neural Networks for Regression (Parts 1-2)

Code

What we covered in this video lecture

So far, we have talked about classification a lot — the most common use case for deep neural networks. However, we can use deep neural networks for regression, too! In this lecture, we saw that we can turn a multilayer perceptron classifier into a regression model with only two minor changes:

Removing the logistic sigmoid / softmax activation function from the output layer; swapping the cross entropy loss with the mean squared error loss.

Additional resources if you want to learn more

If you plan to implement neural networks for regression, also consider using the R-squared coefficient as an evaluation metric. The R2 score is available in TorchMetrics, a library that we will cover in the next unit (unit 5.3).

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: 4.5 Multilayer Neural Networks for Regression

Suppose we have the prediction for three data points: [1.23, 0.51, -2.5] and the corresponding true labels are [-1.0, 0.55, -1.2]. What is the the loss value using the loss function we talked about in the lecture?

Correct. You can double-check the result via PyTorch:

a = torch.tensor([1.23, 0.51, -2.5])
b = torch.tensor([-1.0, 0.55, -1.2])
torch.nn.functional.mse_loss(a, b)

Incorrect. If the predicted data points are stored in tensor a and the true data points are stored in tensor b, the formula for the MSE is 1/3 * sum(a-b)^2.

Incorrect. If the predicted data points are stored in tensor a and the true data points are stored in tensor b, the formula for the MSE is 1/3 * sum(a-b)^2.

Incorrect. The MSE loss can’t be negative.

Incorrect. The MSE loss can’t be negative.

Incorrect. The MSE loss can’t be negative.

Please answer all questions to proceed.
Watch Video 1

Unit 4.5

Videos