Skip to contents

Permutation feature importance (model-agnostic)

Usage

morie_fairness_xai_permutation_importance(
  predict_fn,
  X,
  feature_names = NULL,
  n_repeats = 10L,
  protected = NULL,
  seed = 0L
)

Arguments

predict_fn

Function mapping an (n, d) matrix to n numeric predictions.

X

Numeric matrix or data.frame.

feature_names

Optional character vector.

n_repeats

Shuffles averaged per feature.

protected

Character vector of protected-attribute names; any that rank in the top third trigger a bias warning.

seed

Reproducibility seed.

Value

morie_fairness_result; $value is the largest importance.

Examples

set.seed(1)
X <- matrix(rnorm(400), 100, 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_permutation_importance(predict_fn, X,
  feature_names = colnames(X), n_repeats = 3L, seed = 1L)
#> Permutation Feature Importance
#> ==============================
#>   Top feature     f1
#>   Top importance  1.474
#>   Backend         iml available
#> 
#> The model relies most on 'f1' (importance 1.4740). No protected attribute ranks in the top third.