
Shapley feature attributions for one instance (sampling estimator)
Source:R/fairness_xai.R
morie_fairness_xai_shap_values.RdShapley feature attributions for one instance (sampling estimator)
Usage
morie_fairness_xai_shap_values(
predict_fn,
x,
background,
feature_names = NULL,
n_samples = 200L,
seed = 0L
)Examples
set.seed(11)
X <- matrix(rnorm(120), 30, 4); colnames(X) <- paste0("f", 1:4)
predict_fn <- function(M) as.numeric(M %*% c(1.5, -0.7, 0, 0.3))
morie_fairness_xai_shap_values(predict_fn, X[1L, ], background = X,
feature_names = colnames(X), n_samples = 10L, seed = 1L)
#> SHAP Feature Attributions (sampling estimator)
#> ==============================================
#> Most influential feature f2
#> Its SHAP value 0.73643
#> Prediction 0.24715
#> Background mean -0.43264
#>
#> For this instance the prediction 0.2472 departs from the background mean -0.4326; 'f2' contributes the most (+0.7364). The SHAP values sum to that departure.