Loading...
Implement a function to compute the gradient of the Mean Squared Error (MSE) loss with respect to predictions, a crucial step in training models using optimization techniques. This task involves understanding the mathematical foundation of MSE and its derivative.
The Mean Squared Error is a measure of the average squared difference between predictions y^ and actual targets y, given by the formula n1∑i=1n(y^i−yi)2. To minimize this loss, we need to calculate its gradient with respect to each prediction y^i.
Here are the steps to calculate the gradient:
This technique is widely used in machine learning for training regression models.
mse_gradient([2.0, 4.0], [1.0, 3.0])
[1.0, 1.0]
gradient_i = 2/n × (pred_i - target_i) = 2/2 × 1 = 1 for each