aspect_importance {triplot} | R Documentation |
Calculates importance of variable groups (called aspects) for a selected observation
Description
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.
Usage
aspect_importance(x, ...)
## S3 method for class 'explainer'
aspect_importance(
x,
new_observation,
variable_groups,
N = 1000,
n_var = 0,
sample_method = "default",
f = 2,
...
)
## Default S3 method:
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 |
... |
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_var |
maximum number of non-zero coefficients after lasso fitting, if zero than linear regression is used |
sample_method |
sampling method in |
f |
frequency in |
data |
dataset, it will be extracted from |
predict_function |
predict function, it will be extracted from |
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)
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)