PDP: Partial Dependence Plot (PDP)

View source: R/xAI.R

PDPR Documentation

Partial Dependence Plot (PDP)

Description

Calculates the Partial Dependency Plot for one feature, either numeric or categorical. Returns it as a plot.

Usage

PDP(
  model,
  variable = NULL,
  data = NULL,
  ice = FALSE,
  resolution.ice = 20,
  plot = TRUE,
  parallel = FALSE,
  ...
)

## S3 method for class 'citodnn'
PDP(
  model,
  variable = NULL,
  data = NULL,
  ice = FALSE,
  resolution.ice = 20,
  plot = TRUE,
  parallel = FALSE,
  ...
)

## S3 method for class 'citodnnBootstrap'
PDP(
  model,
  variable = NULL,
  data = NULL,
  ice = FALSE,
  resolution.ice = 20,
  plot = TRUE,
  parallel = FALSE,
  ...
)

Arguments

model

a model created by dnn

variable

variable (as a string) for which the PDP should be computed. If none is supplied, it is computed for all variables.

data

new data on which the PDP should be computed. If NULL, the PDP is computed on the training data.

ice

if TRUE, the Individual Conditional Expectation (ICE) curves are also shown

resolution.ice

resolution (number of grid points) at which the ICE curves are computed

plot

whether to plot the PDP

parallel

whether to parallelize over the bootstrap models

...

arguments passed to predict

Value

A list of plots made with 'ggplot2', one for each selected variable.

Description

Performs a partial dependence plot (PDP) estimation to analyze the relationship between a selected feature and the model's predictions.

The PDP function estimates the partial function \hat{f}_S:

\hat{f}_S(x_S)=\frac{1}{n}\sum_{i=1}^n\hat{f}(x_S,x^{(i)}_{C})

using a Monte Carlo estimation, i.e. it computes the average prediction over the data while the selected feature is held fixed at a given value and the remaining features are kept at their observed values.

For categorical features, every observation is set to each level of the feature in turn, the average prediction per level is calculated, and the result is shown as a bar plot.

If ice = TRUE, the Individual Conditional Expectation (ICE) curves are also shown, with the PDP highlighted in yellow. Each ICE curve illustrates how the prediction for a single observation changes as the feature varies. ICE curves are computed on a value grid rather than at every observed feature value, and are not available for categorical features.

See Also

ALE

Examples


if(torch::torch_is_installed()){
library(cito)

# Build and train  Network
nn.fit<- dnn(Sepal.Length~., data = datasets::iris)

PDP(nn.fit, variable = "Petal.Length")
}


cito documentation built on Nov. 23, 2026, 5:07 p.m.