This function calculates the partial dependence of a model on a single variable. For that predictions are made for all observations in the dataset while varying the value of the variable of interest. The overall partial effect is the average of all predictions. Friedman2001GreedyMachineSDModels

partDependence(object, j, X = NULL, subSample = NULL, mc.cores = 1)

Arguments

object

A model object that has a predict method that takes newdata as argument and returns predictions.

j

The variable for which the partial dependence should be calculated. Either the column index of the variable in the dataset or the name of the variable.

X

The dataset on which the partial dependence should be calculated. Should contain the same variables as the dataset used to train the model. If NULL, tries to extract the dataset from the model object.

subSample

Number of samples to draw from the original data for the empirical partial dependence. If NULL, all the observations are used.

mc.cores

Number of cores to use for parallel computation. Parallel computing is only supported for unix.

Value

An object of class partDependence containing

preds_mean

The average prediction for each value of the variable of interest.

x_seq

The sequence of values for the variable of interest.

preds

The predictions for each value of the variable of interest for each observation.

j

The name of the variable of interest.

xj

The values of the variable of interest in the dataset.

References

See also

Author

Markus Ulmer

Examples

set.seed(1)
x <- rnorm(100)
y <- sign(x) * 3 + rnorm(100)
model <- SDTree(x = x, y = y, Q_type = 'no_deconfounding')
pd <- partDependence(model, 1, X = x, subSample = 10)
plot(pd)