The plot_pdp() function computes and visualizes Partial Dependence Plots (PDP) for a selected feature, following the methodology described in Interpretable Machine Learning by Christoph Molnar. PDPs show the average effect of a feature on model predictions by marginalizing over the distribution of all other features. Optionally, Individual Conditional Expectation (ICE) curves can be added to visualize heterogeneous effects.
plot_pdp(
analysis_object,
feature,
group_by = NULL,
grid_size = 25,
show_ice = TRUE,
ice_n = 50,
pdp_line_size = 1.1,
use_test = FALSE,
plot = TRUE
)If plot = TRUE, returns the updated wrap_object and prints the PDP plot.
If plot = FALSE, returns a ggplot object containing the PDP
(and optionally ICE) visualization.
A fitted wrap_object with model results or
previously computed PDP values.
Character. The continuous feature for which the PDP should be computed.
Optional character. A variable used to produce grouped PDP curves.
Integer. Number of points used to evaluate the PDP (default = 25).
Logical. Whether to overlay ICE curves (default = TRUE).
Integer. Number of ICE curves to sample if show_ice = TRUE
(default = 50).
Numeric. Line width for the PDP curve (default = 1.1).
Logical. Compute PDP using the test set instead of the training set (default = FALSE).
Logical. If TRUE, prints the PDP plot and returns wrap_object;
if FALSE, returns the ggplot object without modifying the object.
Molnar, C. (2022). Interpretable Machine Learning.
https://christophm.github.io/interpretable-ml-book/
sensitivity_analysis
# After fitting model with fine_tuning(wrap_object):
# plot_pdp(wrap_object, feature = "age")
Run the code above in your browser using DataLab