plotD3.aggregated_profiles_explainer {ingredients} | R Documentation |
Plots Aggregated Ceteris Paribus Profiles in D3 with r2d3 Package.
Description
Function plotD3.aggregated_profiles_explainer
plots an aggregate of ceteris paribus profiles.
It works in a similar way to plotD3.ceteris_paribus_explainer
but, instead of individual profiles,
show average profiles for each variable listed in the variables
vector.
Find more details in Ceteris Paribus Chapter.
Usage
## S3 method for class 'aggregated_profiles_explainer'
plotD3(
x,
...,
size = 2,
alpha = 1,
color = "#46bac2",
facet_ncol = 2,
scale_plot = FALSE,
variables = NULL,
chart_title = "Aggregated Profiles",
label_margin = 60
)
Arguments
x |
a aggregated profiles explainer produced with function |
... |
other explainers that shall be plotted together |
size |
a numeric. Set width of lines |
alpha |
a numeric between |
color |
a character. Set line/bar color |
facet_ncol |
number of columns for the |
scale_plot |
a logical. If |
variables |
if not |
chart_title |
a character. Set custom title |
label_margin |
a numeric. Set width of label margins in |
Value
a r2d3
object.
References
Explanatory Model Analysis. Explore, Explain, and Examine Predictive Models. https://ema.drwhy.ai/
Examples
library("DALEX")
library("ingredients")
library("ranger")
# smaller data, quicker example
titanic_small <- select_sample(titanic_imputed, n = 500, seed = 1313)
# build a model
model_titanic_rf <- ranger(survived ~., data = titanic_small, probability = TRUE)
explain_titanic_rf <- explain(model_titanic_rf,
data = titanic_small[,-8],
y = titanic_small[,8],
label = "ranger forest",
verbose = FALSE)
selected_passangers <- select_sample(titanic_small, n = 100)
cp_rf <- ceteris_paribus(explain_titanic_rf, selected_passangers)
pdp_rf_p <- aggregate_profiles(cp_rf, type = "partial", variable_type = "numerical")
pdp_rf_p$`_label_` <- "RF_partial"
pdp_rf_c <- aggregate_profiles(cp_rf, type = "conditional", variable_type = "numerical")
pdp_rf_c$`_label_` <- "RF_conditional"
pdp_rf_a <- aggregate_profiles(cp_rf, type = "accumulated", variable_type = "numerical")
pdp_rf_a$`_label_` <- "RF_accumulated"
plotD3(pdp_rf_p, pdp_rf_c, pdp_rf_a, scale_plot = TRUE)
pdp <- aggregate_profiles(cp_rf, type = "partial", variable_type = "categorical")
pdp$`_label_` <- "RF_partial"
plotD3(pdp, variables = c("gender","class"), label_margin = 70)