ceteris_paribus {ingredients} | R Documentation |
Ceteris Paribus Profiles aka Individual Variable Profiles
Description
This explainer works for individual observations. For each observation it calculates Ceteris Paribus Profiles for selected variables. Such profiles can be used to hypothesize about model results if selected variable is changed. For this reason it is also called 'What-If Profiles'.
Usage
ceteris_paribus(x, ...)
## S3 method for class 'explainer'
ceteris_paribus(
x,
new_observation,
y = NULL,
variables = NULL,
variable_splits = NULL,
grid_points = 101,
variable_splits_type = "quantiles",
...
)
## Default S3 method:
ceteris_paribus(
x,
data,
predict_function = predict,
new_observation,
y = NULL,
variables = NULL,
variable_splits = NULL,
grid_points = 101,
variable_splits_type = "quantiles",
variable_splits_with_obs = FALSE,
label = class(x)[1],
...
)
Arguments
x |
an explainer created with the |
... |
other parameters |
new_observation |
a new observation with columns that corresponds to variables used in the model |
y |
true labels for |
variables |
names of variables for which profiles shall be calculated.
Will be passed to |
variable_splits |
named list of splits for variables, in most cases created with |
grid_points |
maximum number of points for profile calculations. Note that the finaln number of points may be lower than |
variable_splits_type |
how variable grids shall be calculated? Use "quantiles" (default) for percentiles or "uniform" to get uniform grid of points |
data |
validation dataset. It will be extracted from |
predict_function |
predict function. It will be extracted from |
variable_splits_with_obs |
if |
label |
name of the model. By default it's extracted from the |
Details
Find more details in Ceteris Paribus Chapter.
Value
an object of the class ceteris_paribus_explainer
.
References
Explanatory Model Analysis. Explore, Explain, and Examine Predictive Models. https://ema.drwhy.ai/
Examples
library("DALEX")
library("ingredients")
titanic_small <- select_sample(titanic_imputed, n = 500, seed = 1313)
# build a model
model_titanic_glm <- glm(survived ~ gender + age + fare,
data = titanic_small,
family = "binomial")
explain_titanic_glm <- explain(model_titanic_glm,
data = titanic_small[,-8],
y = titanic_small[,8])
cp_rf <- ceteris_paribus(explain_titanic_glm, titanic_small[1,])
cp_rf
plot(cp_rf, variables = "age")
library("ranger")
model_titanic_rf <- ranger(survived ~., data = titanic_imputed, probability = TRUE)
explain_titanic_rf <- explain(model_titanic_rf,
data = titanic_imputed[,-8],
y = titanic_imputed[,8],
label = "ranger forest",
verbose = FALSE)
# select few passangers
selected_passangers <- select_sample(titanic_imputed, n = 20)
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")