plot.individual_variable_profile_explainer: Plots Individual Variable Profile Explanations

Description Usage Arguments Value Examples

View source: R/plot_ceteris_paribus.R

Description

Function 'plot.individual_variable_profile_explainer' plots Individual Variable Profiles for selected observations. Various parameters help to decide what should be plotted, profiles, aggregated profiles, points or rugs.

Usage

1
2
3
4
5
6
7
8
9
## S3 method for class 'individual_variable_profile_explainer'
plot(x, ..., size = 1,
  alpha = 0.3, color = "black", size_points = 2, alpha_points = 1,
  color_points = color, size_rugs = 0.5, alpha_rugs = 1,
  color_rugs = color, size_residuals = 1, alpha_residuals = 1,
  color_residuals = color, only_numerical = TRUE,
  show_profiles = TRUE, show_observations = TRUE, show_rugs = FALSE,
  show_residuals = FALSE, aggregate_profiles = NULL,
  facet_ncol = NULL, selected_variables = NULL)

Arguments

x

a ceteris paribus explainer produced with function 'individual_variable_profile()'

...

other explainers that shall be plotted together

size

a numeric. Size of lines to be plotted

alpha

a numeric between 0 and 1. Opacity of lines

color

a character. Either name of a color or name of a variable that should be used for coloring

size_points

a numeric. Size of points to be plotted

alpha_points

a numeric between 0 and 1. Opacity of points

color_points

a character. Either name of a color or name of a variable that should be used for coloring

size_rugs

a numeric. Size of rugs to be plotted

alpha_rugs

a numeric between 0 and 1. Opacity of rugs

color_rugs

a character. Either name of a color or name of a theme_mi2variable that should be used for coloring

size_residuals

a numeric. Size of line and points to be plotted for residuals

alpha_residuals

a numeric between 0 and 1. Opacity of points and lines for residuals

color_residuals

a character. Either name of a color or name of a variable that should be used for coloring for residuals

only_numerical

a logical. If TRUE then only numerical variables will be plotted. If FALSE then only categorical variables will be plotted.

show_profiles

a logical. If TRUE then profiles will be plotted. Either individual or aggregate (see 'aggregate_profiles')

show_observations

a logical. If TRUE then individual observations will be marked as points

show_rugs

a logical. If TRUE then individual observations will be marked as rugs

show_residuals

a logical. If TRUE then residuals will be plotted as a line ended with a point

aggregate_profiles

function. If NULL (default) then individual profiles will be plotted. If a function (e.g. mean or median) then profiles will be aggregated and only the aggregate profile will be plotted

facet_ncol

number of columns for the 'facet_wrap()'

selected_variables

if not NULL then only 'selected_variables' will be presented

Value

a ggplot2 object

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
library("DALEX2")
 ## Not run: 
library("randomForest")
set.seed(59)

apartments_rf <- randomForest(m2.price ~ construction.year + surface + floor +
                                no.rooms + district, data = apartments)
explainer_rf <- explain(apartments_rf,
                        data = apartments_test[,2:6], y = apartments_test$m2.price)

apartments_lm <- lm(m2.price ~ construction.year + surface + floor +
                                no.rooms + district, data = apartments)
explainer_lm <- explain(apartments_lm,
                        data = apartments_test[,2:6], y = apartments_test$m2.price)

library("e1071")
apartments_svm <- svm(m2.price ~ construction.year + surface + floor +
                                no.rooms + district, data = apartments)
explainer_svm <- explain(apartments_svm,
                        data = apartments_test[,2:6], y = apartments_test$m2.price)

# individual explanations
my_apartment <- apartments_test[1, ]

# for random forest
lp_rf <- individual_variable_profile(explainer_rf, my_apartment)
lp_rf

plot(lp_rf)

# for others
lp_lm <- individual_variable_profile(explainer_lm, my_apartment)
plot(lp_rf, lp_lm, color = "_label_")

# for others
lp_svm <- individual_variable_profile(explainer_svm, my_apartment)
plot(lp_rf, lp_lm, lp_svm, color = "_label_")

# more parameters
plot(lp_rf, lp_lm, lp_svm, color = "_label_",
   show_profiles = TRUE, show_observations = TRUE,
   show_rugs = TRUE,
   alpha = 0.3, alpha_points = 1,
   size_points = 5, size_rugs = 0.5)

plot(lp_rf, show_profiles = TRUE, show_observations = TRUE,
   color = "black",
   selected_variables = c("construction.year", "surface"),
   alpha = 0.3, alpha_points = 1, alpha_residuals = 0.5,
   size_points = 5, size_rugs = 0.5)

plot(lp_rf, show_profiles = TRUE, show_observations = TRUE,
   color = "surface",
   selected_variables = c("construction.year", "surface"),
   alpha = 0.3, alpha_points = 1, alpha_residuals = 0.5,
   size_points = 5, size_rugs = 0.5)

plot(lp_rf, show_profiles = TRUE, show_observations = TRUE,
   color = "darkblue", aggregate_profiles = mean,
   selected_variables = c("construction.year", "surface"),
   alpha = 0.3, alpha_points = 1, alpha_residuals = 0.5,
   size_points = 5, size_rugs = 0.5)

# --------
# multiclass

HR_rf <- randomForest(status ~ . , data = HR)
explainer_rf <- explain(HR_rf, data = HRTest, y = HRTest)

my_HR <- HRTest[1, ]

lp_rf <- individual_variable_profile(explainer_rf, my_HR)
lp_rf

plot(lp_rf, color = "_label_")

## End(Not run)

pbiecek/ceterisParibus2 documentation built on Sept. 16, 2019, 6:26 p.m.