plot_feature_heatmap: Heatmap of LIME Selected Features

Description Usage Arguments Examples

View source: R/plot_feature_heatmap.R

Description

Creates a heatmap of the features selected by lime for all observations in the test set across all of the different LIME implementations.

Usage

1
2
3
4
5
6
plot_feature_heatmap(
  explanations,
  feature_nums = NULL,
  facet_var = NULL,
  order_method = "obs_num"
)

Arguments

explanations

Explain dataframe from the list returned by apply_lime.

feature_nums

A vector of integer values from 1 to nfeatures (specified in apply_lime) to determine which features selected by LIME should be included in the plot.

facet_var

A categorical variable that is the same length as the data input to apply_lime for the test argument that will be used to facet the heatmap. (NULL by default)

order_method

Method for ordering the predictions: either "obs_num" which uses the order from the explanation dataframe (default), "sort_features" which sorts by the factors within a feature using the dplyr "arrange" function, or one of the options from the package seriation for matrices (see seriation::list_seriation_methods("matrix") for the options available.)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Prepare training and testing data
x_train = sine_data_train[c("x1", "x2", "x3")]
y_train = factor(sine_data_train$y)
x_test = sine_data_test[1:5, c("x1", "x2", "x3")]

# Fit a random forest model
rf <- randomForest::randomForest(x = x_train, y = y_train) 

# Run apply_lime
res <- apply_lime(train = x_train, 
                  test = x_test, 
                  model = rf,
                  label = "1",
                  n_features = 2,
                  sim_method = c('quantile_bins',
                                 'kernel_density'),
                  nbins = 2:4)
                  
# Plot heatmap of selected features across LIME implementations
plot_feature_heatmap(res$explain)

# Return a heatmap with only the features selected first by LIME
plot_feature_heatmap(res$explain, feature_num = 1)

goodekat/limeaid documentation built on March 26, 2021, 10:45 p.m.