All problems
Weighted MAE Gradient
Problem
For a weighted mean absolute error, the subgradient for each pair is w_i * sign(pred_i - target_i) with sign 0 at exact ties.
Given predictions, targets, and per-example weights, return the subgradient list.
Hint
Compute the sign first, then scale by the example weight.
Test cases
case 1
in: [[1,2],[2,2],[1,1]]
expected: [-1,0]
case 2
in: [[0,5],[0,0],[2,3]]
expected: [0,3]
case 3
in: [[1,-1],[-1,1],[0.5,0.5]]
expected: [0.5,-0.5]
Starter codePython
def weighted_mae_gradient(preds, targets, weights):
# Your code here
pass3 test cases · run your code against them in the editor