AgnosticWrapper {innsight} | R Documentation |
Super class for model-agnostic interpretability methods
Description
This is a super class for all implemented model-agnostic
interpretability methods and inherits from the InterpretingMethod
class. Instead of just an object of the Converter
class, any model
can now be passed. In contrast to the other model-specific methods in this
package, only the prediction function of the model is required, and not
the internal details of the model. The following model-agnostic methods
are available (all are wrapped by other packages):
-
Shapley values (
SHAP
) based onfastshap::explain
-
Local interpretable model-agnostic explanations (
LIME
) based onlime::lime
Super class
innsight::InterpretingMethod
-> AgnosticWrapper
Public fields
data_orig
The individual instances to be explained by the method (unprocessed!).
Methods
Public methods
Inherited methods
Method new()
Create a new instance of the AgnosticWrapper
R6 class.
Usage
AgnosticWrapper$new( model, data, data_ref, output_type = NULL, pred_fun = NULL, output_idx = NULL, output_label = NULL, channels_first = TRUE, input_dim = NULL, input_names = NULL, output_names = NULL )
Arguments
model
(any prediction model)
A fitted model for a classification or regression task that is intended to be interpreted. AConverter
object can also be passed. In order for the package to know how to make predictions with the given model, a prediction function must also be passed with the argumentpred_fun
. However, for models created bynn_sequential
,keras_model
,neuralnet
orConverter
, these have already been pre-implemented and do not need to be specified.data
(
array
,data.frame
ortorch_tensor
)
The individual instances to be explained by the method. These must have the same format as the input data of the passed model and has to be eithermatrix
, anarray
, adata.frame
or atorch_tensor
. If no value is specified, all instances in the datasetdata
will be explained.
Note: For the model-agnostic methods, only models with a single input and output layer is allowed!data_ref
(
array
,data.frame
ortorch_tensor
)
The dataset to which the method is to be applied. These must have the same format as the input data of the passed model and has to be eithermatrix
, anarray
, adata.frame
or atorch_tensor
.
Note: For the model-agnostic methods, only models with a single input and output layer is allowed!output_type
(
character(1)
)
Type of the model output, i.e., either"classification"
or"regression"
.pred_fun
(
function
)
Prediction function for the model. This argument is only needed ifmodel
is not a model created bynn_sequential
,keras_model
,neuralnet
orConverter
. The first argument ofpred_fun
has to benewdata
, e.g.,function(newdata, ...) model(newdata)
output_idx
(
integer
,list
orNULL
)
These indices specify the output nodes for which the method is to be applied. In order to allow models with multiple output layers, there are the following possibilities to select the indices of the output nodes in the individual output layers:An
integer
vector of indices: If the model has only one output layer, the values correspond to the indices of the output nodes, e.g.,c(1,3,4)
for the first, third and fourth output node. If there are multiple output layers, the indices of the output nodes from the first output layer are considered.A
list
ofinteger
vectors of indices: If the method is to be applied to output nodes from different layers, a list can be passed that specifies the desired indices of the output nodes for each output layer. Unwanted output layers have the entryNULL
instead of a vector of indices, e.g.,list(NULL, c(1,3))
for the first and third output node in the second output layer.-
NULL
(default): The method is applied to all output nodes in the first output layer but is limited to the first ten as the calculations become more computationally expensive for more output nodes.
output_label
(
character
,factor
,list
orNULL
)
These values specify the output nodes for which the method is to be applied. Only values that were previously passed with the argumentoutput_names
in theconverter
can be used. In order to allow models with multiple output layers, there are the following possibilities to select the names of the output nodes in the individual output layers:A
character
vector orfactor
of labels: If the model has only one output layer, the values correspond to the labels of the output nodes named in the passedConverter
object, e.g.,c("a", "c", "d")
for the first, third and fourth output node if the output names arec("a", "b", "c", "d")
. If there are multiple output layers, the names of the output nodes from the first output layer are considered.A
list
ofcharactor
/factor
vectors of labels: If the method is to be applied to output nodes from different layers, a list can be passed that specifies the desired labels of the output nodes for each output layer. Unwanted output layers have the entryNULL
instead of a vector of labels, e.g.,list(NULL, c("a", "c"))
for the first and third output node in the second output layer.-
NULL
(default): The method is applied to all output nodes in the first output layer but is limited to the first ten as the calculations become more computationally expensive for more output nodes.
channels_first
(
logical(1)
)
The channel position of the given data (argumentdata
). IfTRUE
, the channel axis is placed at the second position between the batch size and the rest of the input axes, e.g.,c(10,3,32,32)
for a batch of ten images with three channels and a height and width of 32 pixels. Otherwise (FALSE
), the channel axis is at the last position, i.e.,c(10,32,32,3)
. If the data has no channel axis, use the default valueTRUE
.input_dim
(
integer
)
The model input dimension excluding the batch dimension. It can be specified as vector of integers, but has to be in the format "channels first".input_names
(
character
,factor
orlist
)
The input names of the model excluding the batch dimension. For a model with a single input layer and input axis (e.g., for tabular data), the input names can be specified as a character vector or factor, e.g., for a dense layer with 3 input features usec("X1", "X2", "X3")
. If the model input consists of multiple axes (e.g., for signal and image data), use a list of character vectors or factors for each axis in the format "channels first", e.g., uselist(c("C1", "C2"), c("L1","L2","L3","L4","L5"))
for a 1D convolutional input layer with signal length 4 and 2 channels.
Note: This argument is optional and otherwise the names are generated automatically. But if this argument is set, all found input names in the passed model will be disregarded.output_names
(
character
,factor
)
A character vector with the names for the output dimensions excluding the batch dimension, e.g., for a model with 3 output nodes usec("Y1", "Y2", "Y3")
. Instead of a character vector you can also use a factor to set an order for the plots.
Note: This argument is optional and otherwise the names are generated automatically. But if this argument is set, all found output names in the passed model will be disregarded.
Method clone()
The objects of this class are cloneable with this method.
Usage
AgnosticWrapper$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.