Implement Mean Squared Error Loss

0
easy

In this exercise, you are required to manually compute the Mean Squared Error (MSE) loss between two tensors, representing predicted values and actual values, respectively. The MSE is calculated as the average of the squared differences between corresponding elements in the two tensors. The solution should support tensors of any dimensionality, as long as the input_tensor and target_tensor have the same shape.

MSE=1Ni=1N(yiy^i)2MSE = \frac{1}{N} \sum_{i=1}^{N} (y_i - \hat{y}_i)^2
Where:
  • yiy_i: Each individual actual data point.
  • y^i\hat{y}_i: Each individual predicted data point.
  • MSEMSE: Mean Squared Error between the actual and predicted data points.
  • NN: Total number of data points.

Examples:

1.0
2.0
3.0
1.0
2.5
2.5
0.1666666716337204
3.0
-3.0
0.0
1
0
0
3.0
-2.5
0.5
1
-1
1
0.4166666567325592

Loading...
2024 © TensorGym
Contrinbute | Contact | Copyright | 𝕏