View source: R/ceteris_paribus.R
ceteris_paribus | R Documentation |
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'.
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], ... )
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 |
Find more details in Ceteris Paribus Chapter.
an object of the class ceteris_paribus_explainer
.
Explanatory Model Analysis. Explore, Explain, and Examine Predictive Models. https://ema.drwhy.ai/
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.