Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-299

KernelSHAP Weight

Problem

Compute the KernelSHAP coalition weight for a model with num_features features and a coalition of subset_size: (M - 1) / (C(M, z) * z * (M - z)).

Return 0.0 for endpoint coalitions (z = 0 or z = M) or when M < 2.

Hint

The Shapley kernel assigns the largest weight to small and large coalitions.

Test cases

case 1
in: [4,1]
expected: 0.25
case 2
in: [4,2]
expected: 0.125
case 3
in: [5,2]
expected: 0.06666666666666667
case 4
in: [4,0]
expected: 0
Starter codePython
def kernelshap_weight(num_features, subset_size):
    # Your code here
    pass

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