Skip to main content
. 2022 Mar 18;22(6):2360. doi: 10.3390/s22062360
Algorithm 1 SHAP basic algorithm
  • 1:

    Required: M: Number of interactions; x: Instance of interest; j: Features index; X: Data matrix; f: Machine learning model.

  • 2:

    procedureSHAP(M,x,j,X,f)

  • 3:

        for m=1 in M do

  • 4:

            Draw random instance z from the data matrix X

  • 5:

            Choose a random permutation o of the feature values

  • 6:

            Order instance x: x0=(x(1),...,x(j),...,x(p))

  • 7:

            Order instance z: z0=(z(1),...,z(j),...,z(p))

  • 8:

            Construct two new instances

  • 9:

            Compute marginal contribution ϕjm=f^(x+j)f^(xj)

  • 10:

        end for

  • 11:

        Compute Shapley value as the average ϕj(x)=1Mm=1Mϕjm

  • 12:

    end procedure