R/plotD3_aggregated_profiles.R
plotD3_aggregated_profiles.Rd
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.
# S3 method for 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
)
a aggregated profiles explainer produced with function aggregate_profiles()
other explainers that shall be plotted together
a numeric. Set width of lines
a numeric between 0
and 1
. Opacity of lines
a character. Set line/bar color
number of columns for the facet_wrap
a logical. If TRUE
, the height of plot scales with window size. By default it's FALSE
if not NULL
then only variables
will be presented
a character. Set custom title
a numeric. Set width of label margins in categorical
type
a r2d3
object.
Explanatory Model Analysis. Explore, Explain, and Examine Predictive Models. https://ema.drwhy.ai/
library("DALEX")
library("ingredients")
library("ranger")
# smaller data, quicker example
titanic_small <- select_sample(titanic_imputed, n = 500, seed = 1313)
# \donttest{
# 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)
# }