Predict aspects function takes a sample from a given dataset and modifies it. Modification is made by replacing part of its aspects by values from the observation. Then function is calculating the difference between the prediction made on modified sample and the original sample. Finally, it measures the impact of aspects on the change of prediction by using the linear model or lasso.

aspect_importance(x, ...)

# S3 method for explainer
aspect_importance(
  x,
  new_observation,
  variable_groups,
  N = 1000,
  n_var = 0,
  sample_method = "default",
  f = 2,
  ...
)

# S3 method for default
aspect_importance(
  x,
  data,
  predict_function = predict,
  label = class(x)[1],
  new_observation,
  variable_groups,
  N = 100,
  n_var = 0,
  sample_method = "default",
  f = 2,
  ...
)

lime(x, ...)

predict_aspects(x, ...)

Arguments

x

an explainer created with the DALEX::explain() function or a model to be explained.

...

other parameters

new_observation

selected observation with columns that corresponds to variables used in the model

variable_groups

list containing grouping of features into aspects

N

number of observations to be sampled (with replacement) from data NOTE: Small N may cause unstable results.

n_var

maximum number of non-zero coefficients after lasso fitting, if zero than linear regression is used

sample_method

sampling method in get_sample

f

frequency in get_sample

data

dataset, it will be extracted from x if it's an explainer NOTE: It is best when target variable is not present in the data

predict_function

predict function, it will be extracted from x if it's an explainer

label

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

Value

An object of the class aspect_importance. Contains data frame that describes aspects' importance.

Examples

library("DALEX")

model_titanic_glm <- glm(survived == 1 ~
                         class+gender+age+sibsp+parch+fare+embarked,
                         data = titanic_imputed,
                         family = "binomial")

explain_titanic_glm <- explain(model_titanic_glm,
                               data = titanic_imputed[,-8],
                               y = titanic_imputed$survived == 1,
                               verbose = FALSE)

aspects <- list(wealth = c("class", "fare"),
                family = c("sibsp", "parch"),
                personal = c("gender", "age"),
                embarked = "embarked")

predict_aspects(explain_titanic_glm,
                  new_observation = titanic_imputed[1,],
                  variable_groups = aspects)

# \donttest{
library("randomForest")
library("DALEX")
model_titanic_rf <-
 randomForest(factor(survived) ~ class + gender + age + sibsp +
                parch + fare + embarked,
              data = titanic_imputed)

explain_titanic_rf <- explain(model_titanic_rf,
                              data = titanic_imputed[,-8],
                              y = titanic_imputed$survived == 1,
                              verbose = FALSE)

predict_aspects(explain_titanic_rf,
                  new_observation = titanic_imputed[1,],
                  variable_groups = aspects)

# }