Learn R Programming

DALEXtra (version 0.2.1)

aspect_importance: Calculates the feature groups importance (called aspects importance) for a selected observation

Description

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.

Usage

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, label = class(x)[1], 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

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 dataframe that describes aspects' importance.

Examples

Run this code
# NOT RUN {
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")

aspect_importance(explain_titanic_glm,
                  new_observation = titanic_imputed[1,],
                  aspects = aspects)

# }
# NOT RUN {
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 == 1,
                              verbose = FALSE)

aspect_importance(explain_titanic_rf,
                  new_observation = titanic_imputed[1,],
                  aspects = aspects)

# }
# NOT RUN {
# }

Run the code above in your browser using DataLab