Learn R Programming

MLwrap (version 0.3.0)

plot_pdp: Plot Partial Dependence (PDP)

Description

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.

Usage

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
)

Value

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.

Arguments

analysis_object

A fitted wrap_object with model results or previously computed PDP values.

feature

Character. The continuous feature for which the PDP should be computed.

group_by

Optional character. A variable used to produce grouped PDP curves.

grid_size

Integer. Number of points used to evaluate the PDP (default = 25).

show_ice

Logical. Whether to overlay ICE curves (default = TRUE).

ice_n

Integer. Number of ICE curves to sample if show_ice = TRUE (default = 50).

pdp_line_size

Numeric. Line width for the PDP curve (default = 1.1).

use_test

Logical. Compute PDP using the test set instead of the training set (default = FALSE).

plot

Logical. If TRUE, prints the PDP plot and returns wrap_object; if FALSE, returns the ggplot object without modifying the object.

References

Molnar, C. (2022). Interpretable Machine Learning.
https://christophm.github.io/interpretable-ml-book/

See Also

sensitivity_analysis

Examples

Run this code
# After fitting model with fine_tuning(wrap_object):
# plot_pdp(wrap_object, feature = "age")

Run the code above in your browser using DataLab