This function computes the SHAP values of each rule and arranges them in a matrix that can be used to compute SHAP values of the model as a whole.
ShapleyMats(
data,
data_test = data,
Rs,
Rs_test = Rs,
id_mat,
interactions = FALSE
)marginal A matrix with \(n\cdot p\) rows and as many columns as there are terms (both linear and rules). It is obtained by vertically stacking matrices of \(n\) rows. Each submatrix focuses on the SHAP values of a different predictor: the \((i,k)\)-th entry of the \(j\)-th of such submatrices represents the contribution of the \(k\)-th term to the SHAP value of the \(i\)-th datapoint for the \(j\)-th predictor. The first \(p\) terms are the linear terms, and the remaining columns refer to the rules.
interaction A matrix with \(n\cdot p^2\) rows and as many columns as there are terms (both linear and rules). It is obtained by vertically stacking matrices of \(n \cdot p\) rows. Each submatrix is in turn split into \(p\) subsubmatrices which focuses on the interaction SHAP values of a different pair of predictors: the \((i,k)\)-th entry of the \(j\)-th subsubmatrix of the \(j'\)-th submatrix represents the contribution of the \(k\)-th term to the SHAP value of the \(i\)-th datapoint for the interaction between the \(j\)-th and the \(j'\)-th predictor. The first \(p\) terms are the linear terms, and the remaining columns refer to the rules.
a dataframe containing the data used to estimate the expectations in SHAP values
a dataframe containing the points to compute the SHAP values of. By default, this coincides with the datapoints used to estimate SHAP values.
a list of as many matrices as there are rules to compute the SHAP values for.
The \(j\)-th element is a matrix corresponding to the \(j\)-th rule. Each of its columns
corresponds to the 0-1 encoding of a subrule of the \(j\)-th rule, as observed in the data
provided with input parameter data. Can be computed with the RuleMats function.
same as Rs, but computed for the (possibly different) observations provided
from the data_test parameter.
A matrix with as many rows as there are rules and as many columns as there are predictors. The \(j\)-th column has ones on the entries corresponding to rules that involve the \(j\)-th predictor, while all remaining entries are zeroes. Can be computed with the RuleMats function.
A logical parameter determining whether interaction SHAP values should also be computed.
Giorgio Spadaccini
Code written by and used with permission from Giorgio Spadaccini.