ingredients (version 0.3.1)

plot.ceteris_paribus_explainer: Plots Ceteris Paribus Profiles

Description

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

Usage

# S3 method for ceteris_paribus_explainer
plot(x, ..., size = 1, alpha = 1,
  color = "#46bac2", only_numerical = TRUE, facet_ncol = NULL,
  variables = NULL)

Arguments

x

a ceteris paribus explainer produced with function `ceteris_paribus()`

...

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

only_numerical

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

facet_ncol

number of columns for the `facet_wrap()`

variables

if not NULL then only `variables` will be presented

Value

a ggplot2 object

Details

Find more detailes in Ceteris Paribus Chapter.

References

Predictive Models: Visual Exploration, Explanation and Debugging https://pbiecek.github.io/PM_VEE

Examples

Run this code
# NOT RUN {
library("DALEX")
# Toy examples, because CRAN angels ask for them
titanic <- na.omit(titanic)
model_titanic_glm <- glm(survived == "yes" ~ gender + age + fare,
                       data = titanic, family = "binomial")

explain_titanic_glm <- explain(model_titanic_glm,
                           data = titanic[,-9],
                           y = titanic$survived == "yes")
cp_rf <- ceteris_paribus(explain_titanic_glm, titanic[1,])
cp_rf
plot(cp_rf, variables = "age")

 
# }
# NOT RUN {
 library("randomForest")
 model_titanic_rf <- randomForest(survived == "yes" ~ gender + age + class + embarked +
                                    fare + sibsp + parch,  data = titanic)
 model_titanic_rf

 explain_titanic_rf <- explain(model_titanic_rf,
                           data = titanic[,-9],
                           y = titanic$survived == "yes",
                           label = "Random Forest v7")

selected_passangers <- select_sample(titanic, n = 100)
cp_rf <- ceteris_paribus(explain_titanic_rf, selected_passangers)
cp_rf

plot(cp_rf, variables = "age") +
show_observations(cp_rf, variables = "age") +
  show_rugs(cp_rf, variables = "age", color = "red")

# }

Run the code above in your browser using DataCamp Workspace