Learn R Programming

triplot (version 1.3.0)

calculate_triplot: Calculate triplot that sums up automatic aspect/feature importance grouping

Description

This function shows:

  • plot for the importance of single variables,

  • tree that shows importance for every newly expanded group of variables,

  • clustering tree.

Usage

calculate_triplot(x, ...)

# S3 method for explainer calculate_triplot( x, type = c("predict", "model"), new_observation = NULL, N = 1000, loss_function = DALEX::loss_root_mean_square, B = 10, fi_type = c("raw", "ratio", "difference"), clust_method = "complete", cor_method = "spearman", ... )

# S3 method for default calculate_triplot( x, data, y = NULL, predict_function = predict, label = class(x)[1], type = c("predict", "model"), new_observation = NULL, N = 1000, loss_function = DALEX::loss_root_mean_square, B = 10, fi_type = c("raw", "ratio", "difference"), clust_method = "complete", cor_method = "spearman", ... )

# S3 method for triplot print(x, ...)

model_triplot(x, ...)

predict_triplot(x, ...)

Arguments

x

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

...

other parameters

type

if predict then aspect_importance is used, if model than feature_importance is calculated

new_observation

selected observation with columns that corresponds to variables used in the model, should be without target variable

N

number of rows to be sampled from data NOTE: Small N may cause unstable results.

loss_function

a function that will be used to assess variable importance, if type = model

B

integer, number of permutation rounds to perform on each variable in feature importance calculation, if type = model

fi_type

character, type of transformation that should be applied for dropout loss, if type = model. "raw" results raw drop losses, "ratio" returns drop_loss/drop_loss_full_model.

clust_method

the agglomeration method to be used, see hclust methods

cor_method

the correlation method to be used see cor methods

data

dataset, it will be extracted from x if it's an explainer NOTE: Target variable shouldn't be present in the data

y

true labels for data, will be extracted from x if it's an explainer

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

triplot object

Examples

Run this code
# NOT RUN {
library(DALEX)
set.seed(123)
apartments_num <- apartments[,unlist(lapply(apartments, is.numeric))]
apartments_num_lm_model <- lm(m2.price ~ ., data = apartments_num)
apartments_num_new_observation <- apartments_num[30, ]
explainer_apartments <- explain(model = apartments_num_lm_model,
                                data = apartments_num[,-1],
                                y = apartments_num[, 1],
                                verbose = FALSE)
apartments_tri <- calculate_triplot(x = explainer_apartments,
                                    new_observation =
                                      apartments_num_new_observation[-1])
apartments_tri
                                   

# }

Run the code above in your browser using DataLab