aspect_importance: Calculates the feature groups importance (called aspects...

Description Usage Arguments Value Examples

View source: R/aspect_importance.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
aspect_importance(x, ...)

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

## Default S3 method:
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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)


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)

ModelOriented/DALEXtra documentation built on Jan. 17, 2020, 1:55 a.m.