All problems
MSE Gradient Per Element
Problem
For mean squared error L = (1/n) * sum_i (pred_i - target_i)^2, the gradient with respect to each prediction is 2 * (pred_i - target_i) / n.
Given predictions and targets, return the gradient list.
Hint
The 1/n from the mean scales every element.
Test cases
case 1
in: [[1,2],[0,0]]
expected: [1,2]
case 2
in: [[1,1,1],[1,1,1]]
expected: [0,0,0]
case 3
in: [[0,3],[1,1]]
expected: [-1,2]
Starter codePython
def mse_gradient_per_element(preds, targets):
# Your code here
pass3 test cases · run your code against them in the editor