Add black box predictions to generated dataset

add_predictions(to_explain, black_box_model, data = NULL,
  predict_fun = predict, hyperparams = list(), ...)

Arguments

to_explain

List return by sample_locally function.

black_box_model

String with mlr signature of a learner or a model with predict interface.

data

Original data frame used to generate new dataset. Need not be provided when a trained model is passed in black_box_model argument.

predict_fun

Either a "predict" function that returns a vector of the same type as response or custom function that takes a model as a first argument, and data used to calculate predictions as a second argument and returns a vector of the same type as respone. Will be used only if a model object was provided in the black_box argument.

hyperparams

Optional list of (hyper)parameters to be passed to mlr::makeLearner.

...

Additional parameters to be passed to predict function.

Value

list of class "live_explorer" consisting of

data

Dataset generated by sample_locally function with response variable.

target

Name of the response variable.

model

Black box model which is being explained.

explained_instance

Instance that is being explained.

sampling_method

Name of used sampling method

fixed_variables

Names of variables which were not sampled

sdevations

Standard deviations of numerical variables

Examples

# NOT RUN {
# Train a model inside add_predictions call.
local_exploration1 <- add_predictions(dataset_for_local_exploration,
                                      black_box_model = "regr.svm",
                                      data = wine)
# Pass trained model to the function.
svm_model <- svm(quality ~., data = wine)
local_exploration2 <- add_predictions(dataset_for_local_exploration,
                                      black_box_model = svm_model)
# }