Skip to contents

Simple wrappers around iml classes to provide a more streamlined approach for generating interpretable plots and explanatory data.

Usage

iml_regularize(data, features = names(sapply(data, is.numeric)))

iml_predictor(
  model,
  data,
  predict.function = NULL,
  y = NULL,
  regularize = TRUE
)

iml_featureimp(
  model,
  data,
  loss = "logLoss",
  compare = "difference",
  n.repetitions = 5,
  features = NULL
)

iml_featureeffects(
  model,
  data,
  features = NULL,
  method = "ale",
  center.at = NULL,
  grid.size = 20
)

iml_shapley(model, data, x.interest = NULL, sample.size = 100)

Arguments

data

data.table of a test dataset

features

character The names of the features for which to compute the feature effects/importance.

model

mlr3::Learner model, pre-trained

predict.function

function function to predict newdata. The first argument is the model, the second the newdata.

y

character(1)|numeric|factor The target vector or (preferably) the name of the target column in the data argument. Predictor tries to infer the target automatically from the model.

regularize

logical(1) whether or not to pass the data through iml_regularize

loss

character(1)|function. The loss function. Either the name of a loss (e.g. "ce" for classification or "mse") or a function.

compare

character(1) Either "ratio" or "difference".

n.repetitions

numeric(1) How many shufflings of the features should be done?

method

character(1)

  • 'ale' for accumulated local effects,

  • 'pdp' for partial dependence plot,

  • 'ice' for individual conditional expectation curves,

  • 'pdp+ice' for partial dependence plot and ice curves within the same plot.

center.at

numeric(1) Value at which the plot should be centered. Ignored in the case of two features.

grid.size

numeric(1) The size of the grid for evaluating the predictions.

x.interest

data.frame data to be explained.

sample.size

numeric(1) The number of Monte Carlo samples for estimating the Shapley value.

Value

Functions

  • iml_regularize(): regularize data for iml by replacing NA's and adding small random noise to constant columns

  • iml_predictor(): wrapper for iml::Predictor to subset the features of data and provide a predict.function and y when the predictor can't identify them.

  • iml_featureimp(): wrapper for iml::FeatureImp that handles predictor creation and multiprocessing

  • iml_featureeffects(): wrapper for iml::FeatureEffects that handles data filtering, predictor creation and multiprocessing

  • iml_shapley(): wrapper for iml::Shapley that handles predictor creation and multiprocessing