1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Deep Learning with PyTorch

Connected

Exercise

Using the MSELoss

For regression problems, you often use Mean Squared Error (MSE) as a loss function instead of cross-entropy. MSE calculates the squared difference between predicted values (y_pred) and actual values (y). Now, you'll compute MSE loss using both NumPy and PyTorch.

torch, numpy (as np), and torch.nn (as nn) packages are already imported.

Instructions

100 XP
  • Calculate the MSE loss using NumPy.
  • Create an MSE loss function using PyTorch.
  • Convert y_pred and y to tensors, then calculate the MSE loss as mse_pytorch.