All problems
Linear SHAP Contribution
Problem
Compute linear SHAP contributions for one point: phi_j = w_j * (x_j - background_mean_j).
Return the list of contributions; empty input returns [].
Hint
For a linear model each feature's SHAP value is its weight times its deviation from the background mean.
Test cases
case 1
in: [[5,10],[2,-1],[3,8]]
expected: [4,-2]
case 2
in: [[1],[3],[2]]
expected: [-3]
case 3
in: [[0.5,1.5],[-2,4],[0.5,0.5]]
expected: [0,4]
case 4
in: [[],[],[]]
expected: []
Starter codePython
def linear_shap_values(x, w, background_means):
# Your code here
pass4 test cases · run your code against them in the editor