Aspect Importance 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, aspects,
  N = 100, sample_method = "default", n_var = 0, f = 2,
  show_cor = FALSE, ...)

# S3 method for default
aspect_importance(x, data, predict_function = predict,
  new_observation, aspects, N = 100, sample_method = "default",
  n_var = 0, f = 2, show_cor = FALSE, ...)

lime(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

aspects

list containting grouping of features into aspects

N

number of observations to be sampled (with replacement) from data

sample_method

sampling method in get_sample

n_var

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

f

frequency in get_sample

show_cor

show if all features in aspect are pairwise positivly correlated, works only if dataset contains solely numeric values

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

Value

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

Examples

library("DALEX") titanic_imputed$country <- NULL model_titanic_glm <- glm(survived == "yes" ~ 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 == "yes", verbose = FALSE) aspects <- list(wealth = c("class", "fare"), family = c("sibsp", "parch"), personal = c("gender", "age"), embarked = "embarked") aspect_importance(explain_titanic_glm, new_observation = titanic_imputed[1,], aspects = aspects)
#> aspects importance features #> 2 wealth -0.141919 class, fare #> 4 personal -0.140710 gender, age #> 5 embarked -0.019205 embarked #> 3 family 0.006887 sibsp, parch
# \donttest{ library("randomForest") model_titanic_rf <- randomForest(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 == "yes", verbose = FALSE) aspect_importance(explain_titanic_rf, new_observation = titanic_imputed[1,], aspects = aspects)
#> aspects importance features #> 4 personal -0.11158 gender, age #> 2 wealth -0.10722 class, fare #> 5 embarked -0.02662 embarked #> 3 family 0.01313 sibsp, parch
# }