Black-box models may have very different structures. This function creates a unified representation of a model, which can be further processed by various explainers.

explain.default(model, data = NULL, y = NULL,
  predict_function = yhat, link = I, ..., label = tail(class(model),
  1))

explain(model, data = NULL, y = NULL, predict_function = yhat,
  link = I, ..., label = tail(class(model), 1))

Arguments

model

object - a model to be explained

data

data.frame or matrix - data that was used for fitting. If not provided then will be extracted from the model

y

numeric vector with outputs / scores. Currently used only by variable_dropout() explainer.

predict_function

function that takes two arguments: model and new data and returns numeric vector with predictions

link

function - a transformation/link function that shall be applied to raw model predictions

...

other parameters

label

character - the name of the model. By default it's extracted from the 'class' attribute of the model

Value

An object of the class 'explainer'.

It's a list with following fields:

  • model the explained model

  • data the dataset used for training

  • predict_function function that may be used for model predictions, shall return a single numerical value for each observation.

  • class class/classes of a model

  • label label, by default it's the last value from the class vector, but may be set to any character.

Details

Please NOTE, that the model is actually the only required argument. But some explainers may require that others will be provided too.

Examples

apartments_lm <- lm(m2.price ~ ., data = apartments) apartments_lm_ex <- explain(apartments_lm, data = apartments, label = "apartments_lm") apartments_lm_ex
#> Model label: apartments_lm #> Model class: lm #> Data head : #> m2.price construction.year surface floor no.rooms district #> 1 5897 1953 25 3 1 Srodmiescie #> 2 1818 1992 143 9 5 Bielany
library("breakDown2") wine_lm_model4 <- lm(quality ~ pH + residual.sugar + sulphates + alcohol, data = wine)
#> Error in is.data.frame(data): object 'wine' not found
wine_lm_explainer4 <- explain(wine_lm_model4, data = wine, label = "model_4v")
#> Error in explain(wine_lm_model4, data = wine, label = "model_4v"): object 'wine' not found
wine_lm_explainer4
#> Error in eval(expr, envir, enclos): object 'wine_lm_explainer4' not found
library("randomForest") wine_rf_model4 <- randomForest(quality ~ pH + residual.sugar + sulphates + alcohol, data = wine)
#> Error in eval(m$data, parent.frame()): object 'wine' not found
wine_rf_explainer4 <- explain(wine_rf_model4, data = wine, label = "model_rf")
#> Error in explain(wine_rf_model4, data = wine, label = "model_rf"): object 'wine' not found
wine_rf_explainer4
#> Error in eval(expr, envir, enclos): object 'wine_rf_explainer4' not found