ingredients (version 0.3.1)

partial_dependency: Partial Dependency Profiles

Description

Partial Dependency Profiles are averages from Ceteris Paribus Profiles. Function 'partial_dependency' calls 'ceteris_paribus' and then 'aggregate_profiles'.

Usage

partial_dependency(x, ...)

# S3 method for explainer partial_dependency(x, variables = NULL, N = 500, variable_splits = NULL, grid_points = 101, ...)

# S3 method for default partial_dependency(x, data, predict_function = predict, label = class(x)[1], variables = NULL, grid_points = grid_points, variable_splits = variable_splits, N = 500, ...)

# S3 method for ceteris_paribus_explainer partial_dependency(x, ..., variables = NULL)

Arguments

x

a model to be explained, or an explainer created with function `DALEX::explain()` or object of the class `ceteris_paribus_explainer`.

...

other parameters

variables

names of variables for which profiles shall be calculated. Will be passed to `calculate_variable_splits()`. If NULL then all variables from the validation data will be used.

N

number of observations used for calculation of partial dependency profiles. By default 500.

variable_splits

named list of splits for variables, in most cases created with `calculate_variable_splits()`. If NULL then it will be calculated based on validation data avaliable in the `explainer`.

grid_points

number of points for profile. Will be passed to `calculate_variable_splits()`.

data

validation dataset, will be extracted from `x` if it's an explainer

predict_function

predict function, will be extracted from `x` if it's an explainer

label

name of the model. By default it's extracted from the 'class' attribute of the model

Value

an 'aggregated_profiles_explainer' layer

Details

Find more detailes in the Partial Dependence Profiles 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")

pdp_rf <- partial_dependency(explain_titanic_glm, N = 50)
plot(pdp_rf)

# }
# NOT RUN {
 library("randomForest")
 model_titanic_rf <- randomForest(survived ~ 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,
                           label = "Random Forest v7")

pdp_rf <- partial_dependency(explain_titanic_rf, variables = "age")
plot(pdp_rf)

pdp_rf <- partial_dependency(explain_titanic_rf)
plot(pdp_rf)
# }

Run the code above in your browser using DataLab