Function show_observations
adds a layer to a plot created with
plot.ceteris_paribus_explainer
for selected observations.
Various parameters help to decide what should be plotted, profiles, aggregated profiles, points or rugs.
show_observations(
x,
...,
size = 2,
alpha = 1,
color = "#371ea3",
variable_type = "numerical",
variables = NULL
)
a ceteris paribus explainer produced with function ceteris_paribus()
other explainers that shall be plotted together
a numeric. Size of lines to be plotted
a numeric between 0
and 1
. Opacity of lines
a character. Either name of a color or name of a variable that should be used for coloring
a character. If numerical
then only numerical variables will be plotted.
If categorical
then only categorical variables will be plotted.
if not NULL
then only variables
will be presented
a ggplot2
layer
Explanatory Model Analysis. Explore, Explain, and Examine Predictive Models. https://ema.drwhy.ai/
library("DALEX")
library("ingredients")
# \donttest{
library("ranger")
rf_model <- ranger(survived ~., data = titanic_imputed, probability = TRUE)
explainer_rf <- explain(rf_model,
data = titanic_imputed[,-8],
y = titanic_imputed[,8],
label = "ranger forest",
verbose = FALSE)
selected_passangers <- select_sample(titanic_imputed, n = 100)
cp_rf <- ceteris_paribus(explainer_rf, selected_passangers)
cp_rf
#> Top profiles :
#> gender age class embarked fare sibsp parch _yhat_
#> 515 female 45 2nd Southampton 10.1000 0 0 0.8168505
#> 515.1 male 45 2nd Southampton 10.1000 0 0 0.1059383
#> 604 female 17 3rd Southampton 7.1701 1 0 0.4675747
#> 604.1 male 17 3rd Southampton 7.1701 1 0 0.1167633
#> 1430 female 25 engineering crew Southampton 0.0000 0 0 0.7796172
#> 1430.1 male 25 engineering crew Southampton 0.0000 0 0 0.2402162
#> _vname_ _ids_ _label_
#> 515 gender 515 ranger forest
#> 515.1 gender 515 ranger forest
#> 604 gender 604 ranger forest
#> 604.1 gender 604 ranger forest
#> 1430 gender 1430 ranger forest
#> 1430.1 gender 1430 ranger forest
#>
#>
#> Top observations:
#> gender age class embarked fare sibsp parch _yhat_
#> 515 male 45 2nd Southampton 10.1000 0 0 0.1059383
#> 604 male 17 3rd Southampton 7.1701 1 0 0.1167633
#> 1430 male 25 engineering crew Southampton 0.0000 0 0 0.2402162
#> 865 male 20 3rd Cherbourg 7.0406 0 0 0.1177738
#> 452 female 17 3rd Queenstown 7.1408 0 0 0.6502409
#> 1534 male 38 victualling crew Southampton 0.0000 0 0 0.1697892
#> _label_ _ids_
#> 515 ranger forest 1
#> 604 ranger forest 2
#> 1430 ranger forest 3
#> 865 ranger forest 4
#> 452 ranger forest 5
#> 1534 ranger forest 6
plot(cp_rf, variables = "age", color = "grey") +
show_observations(cp_rf, variables = "age", color = "black") +
show_rugs(cp_rf, variables = "age", color = "red")
# }