Skip to content
DeepForgeby svx
All problems
MediumCalculusca-330

Weighted MSE Gradient

Problem

For f(w) = sum_i c_i (w_i - t_i)^2 with per-coordinate weights c_i, the gradient entry is 2 c_i (w_i - t_i).

Given w, t, and the weights, return the gradient list.

Hint

Each weight scales its own squared residual term.

Test cases

case 1
in: [[1,2],[0,0],[1,1]]
expected: [2,4]
case 2
in: [[1,1],[0,0],[2,0.5]]
expected: [4,1]
case 3
in: [[3],[1],[10]]
expected: [40]
Starter codePython
def weighted_mse_gradient(w, t, weights):
    # Your code here
    pass

3 test cases · run your code against them in the editor