All problems
Two-Feature Shapley Values
Problem
Compute exact Shapley values for a two-feature model with an interaction. The empty-set value is 0, the individual feature values are v1 and v2, and the joint value is v12. Feature 1 gets 0.5*v1 + 0.5*(v12 - v2) and feature 2 gets 0.5*v2 + 0.5*(v12 - v1). Return [shap1, shap2].
Hint
With only two features each Shapley value averages the marginal contribution over both orderings.
Test cases
case 1
in: [1,2,4]
expected: [1.5,2.5]
case 2
in: [0,0,0]
expected: [0,0]
case 3
in: [3,1,3]
expected: [2.5,0.5]
case 4
in: [-1,2,1]
expected: [-1,2]
Starter codePython
def shapley_two_features(v1, v2, v12):
# Returns [shap1, shap2]
# Your code here
pass4 test cases · run your code against them in the editor