Function plotD3.ceteris_paribus_explainer plots Individual Variable Profiles for selected observations. It uses output from ceteris_paribus function. Various parameters help to decide what should be plotted, profiles, aggregated profiles, points or rugs.

Find more detailes in Ceteris Paribus Chapter.

plotD3(x, ...)

# S3 method for ceteris_paribus_explainer
plotD3(x, ..., size = 2, alpha = 1,
  color = "#46bac2", variable_type = "numerical", facet_ncol = 2,
  scale_plot = FALSE, variables = NULL,
  chart_title = "Ceteris Paribus Profiles", label_margin = 60,
  show_observations = TRUE, show_rugs = TRUE)

Arguments

x

a ceteris paribus explainer produced with function ceteris_paribus()

...

other explainers that shall be plotted together

size

a numeric. Set width of lines

alpha

a numeric between 0 and 1. Opacity of lines

color

a character. Set line color

variable_type

a character. If "numerical" then only numerical variables will be plotted. If "categorical" then only categorical variables will be plotted.

facet_ncol

number of columns for the facet_wrap

scale_plot

a logical. If TRUE, the height of plot scales with window size. By default it's FALSE

variables

if not NULL then only variables will be presented

chart_title

a character. Set custom title

label_margin

a numeric. Set width of label margins in categorical type

show_observations

a logical. Adds observations layer to a plot. By default it's TRUE

show_rugs

a logical. Adds rugs layer to a plot. By default it's TRUE

Value

a r2d3 object.

Examples

library("DALEX") library("randomForest") model_titanic_rf <- randomForest(survived ~., data = titanic_imputed)
#> Warning: The response has five or fewer unique values. Are you sure you want to do regression?
explain_titanic_rf <- explain(model_titanic_rf, data = titanic_imputed[,-8], y = titanic_imputed[,8], label = "rf")
#> Preparation of a new explainer is initiated #> -> model label : rf #> -> data : 2207 rows 7 cols #> -> target variable : 2207 values #> -> predict function : yhat.randomForest will be used ( default ) #> -> predicted values : numerical, min = 0.0113124 , mean = 0.3227786 , max = 0.9904428 #> -> residual function : difference between y and yhat ( default ) #> -> residuals : numerical, min = -0.8058614 , mean = -0.0006218405 , max = 0.8996748 #> -> model_info : package randomForest , ver. 4.6.14 , task regression ( default ) #> A new explainer has been created!
selected_passangers <- select_sample(titanic_imputed, n = 10) cp_rf <- ceteris_paribus(explain_titanic_rf, selected_passangers) plotD3(cp_rf, variables = c("age","parch","fare","sibsp"), facet_ncol = 2, scale_plot = TRUE) selected_passanger <- select_sample(titanic_imputed, n = 1) cp_rf <- ceteris_paribus(explain_titanic_rf, selected_passanger) plotD3(cp_rf, variables = c("class", "embarked", "gender", "sibsp"), facet_ncol = 2, variable_type = "categorical", label_margin = 100, scale_plot = TRUE)