interpret: Model-agnostic interpretation (global + local).

View source: R/interpret.R

interpretR Documentation

Model-agnostic interpretation (global + local).

Description

Implements native permutation VI, PDP/ICE/ALE, SHAP approximations, local surrogate explanations, interaction strength, and global surrogate models.

Usage

interpret(
  fit,
  data,
  formula = fit$formula,
  method = c("vip", "permute", "pdp", "ice", "ale", "local", "lime", "shap",
    "local_model", "interaction", "surrogate", "profile", "ceteris_paribus",
    "calibration", "dca"),
  features = NULL,
  type = NULL,
  metric = NULL,
  importance_type = c("permute", "model", "auto"),
  compare = c("difference", "ratio"),
  keep = TRUE,
  k = NULL,
  gower_power = NULL,
  class_level = NULL,
  pos_level = NULL,
  newdata = NULL,
  nsim = NULL,
  nsamples = NULL,
  grid = NULL,
  seed = NULL,
  bins = 10,
  strategy = c("quantile", "uniform"),
  ncores = NULL,
  ...
)

Arguments

fit

A funcml_fit object.

data

Reference data (typically training set).

formula

Optional formula (defaults to fit$formula).

method

One of "vip","permute","pdp","ice","ale","local","lime", "shap","local_model","interaction","surrogate","profile", "ceteris_paribus", or "calibration".

features

Optional subset of features; defaults to all predictors.

type

Prediction scale: regression -> "response"; classification -> "prob" or "class".

metric

Loss/score for importance (reg: rmse/mae/mse/medae/mape/rsq; cls: accuracy/precision/recall/specificity/f1/balanced_accuracy/logloss/brier/ece/mce/auc/auc_weighted).

importance_type

Importance engine for method = "vip". Internal permutation importance is always used; accepted values are retained only for backward-compatible argument parsing.

compare

How to compare baseline and perturbed performance for importance: "difference" or "ratio".

keep

Keep per-repetition raw importance scores when nsim > 1.

k

Sparsity target for local surrogate fits (method = "local", "local_model", or "lime").

gower_power

Exponent applied to native similarity weights when constructing the local neighborhood.

class_level

Target class for multiclass/local prob explanations.

pos_level

Alias for binary positive class (second level default).

newdata

Single-row data frame for local/SHAP explanations; defaults to first row of data.

nsim

Number of Monte Carlo simulations (importance/SHAP) or repetitions.

nsamples

Row subsample for speed (reference/background set).

grid

Optional list of grids per feature for PDP/ICE/ALE.

seed

Optional seed for determinism.

bins

Number of bins for calibration diagnostics.

strategy

Binning strategy for calibration diagnostics.

ncores

Optional number of CPU cores used to parallelize the per-observation SHAP computation (method = "shap"). NULL or 1 runs sequentially. Ignored by other methods, and ignored (with a warning) for xgboost, lightgbm, mlp, densemlp, and bart fits on Unix, since reusing their fitted state across a forked process is unsafe.

...

Additional method-specific args.

Value

An interpretation object whose class depends on method. Returned objects contain computed explanation values and metadata used for printing, summarizing, and plotting.

Examples

fit_obj <- fit(
  mpg ~ wt + hp + disp,
  data = mtcars,
  model = "rpart",
  spec = list(cp = 0.01, minsplit = 5)
)
vi <- interpret(
  fit = fit_obj,
  data = mtcars,
  method = "permute",
  features = c("wt", "hp"),
  nsim = 2,
  metric = "rmse"
)
vi$result$scores

funcml documentation built on Aug. 22, 2026, 5:08 p.m.