Learn R Programming

iml (version 0.9.0)

FeatureEffects: Effect of all features on predictions

Description

FeatureEffects computes feature effects for multiple features at once.

Format

R6Class object.

Usage

effects = FeatureEffects$new(predictor, features = NULL, method = "ale", 
    grid.size = 20, center.at = NULL, parallel = FALSE)

plot(effects) effects$results print(effects)

Arguments

For FeatureEffects$new():

predictor:

(Predictor) The object (created with Predictor$new()) holding the machine learning model and the data.

features:

(`character()`) The names of the features for which the effects should be computed. Default is all features used in the prediction model.

method:

(`character(1)`) 'ale' for accumulated local effects (the default), 'pdp' for partial dependence plot, 'ice' for individual conditional expectation curves, 'pdp+ice' for partial dependence plot and ice curves within the same plot.

center.at:

(`numeric(1)`) Value at which the plot should be centered.

grid.size:

(`numeric(1)` | `numeric(2)`) The size of the grid for evaluating the predictions

parallel:

`logical(1)` Should the method be executed in parallel? If TRUE, requires a cluster to be registered, see ?foreach::foreach.

Fields

method:

(`character(1)`) 'ale' for accumulated local effects, 'pdp' for partial dependence plot, 'ice' for individual conditional expectation curves, 'pdp+ice' for partial dependence plot and ice curves within the same plot.

features:

(`character()`) The names of the features for which the effects were computed.

grid.size:

(`numeric(1)` | `numeric(2)`) The size of the grid.

center.at:

(`numeric(1)` | `character(1)`) The value for the centering of the plot. Numeric for numeric features, and the level name for factors.

predictor:

(Predictor) The prediction model that was analysed.

results:

(list) A list with the results of each feature effect. Each entry is a data.frame with the grid of feature of interest and the predicted \(\hat{y}\). Can be used for creating custom effect plots.

effects:

(list) A list of the FeatureEffect objects for each feature. See ?FeatureEffect what you can do with them (e.g. plot them individually).

Methods

plot()

method to plot the all effects. See plot.FeatureEffects

clone()

[internal] method to clone the R6 object.

initialize()

[internal] method to initialize the R6 object.

Details

FeatureEffects computes the effects for all given features on the model prediction. FeatureEffects is a convenience class that calls FeatureEffect multiple times. See ?FeatureEffect for details what's actually computed.

Only first-order effects can be computed with the FeatureEffects interface. If you are intereated in the visualization of interactions between two features, directly use FeatureEffect.

References

Apley, D. W. 2016. "Visualizing the Effects of Predictor Variables in Black Box Supervised Learning Models." ArXiv Preprint.

Friedman, J.H. 2001. "Greedy Function Approximation: A Gradient Boosting Machine." Annals of Statistics 29: 1189-1232.

Goldstein, A., Kapelner, A., Bleich, J., and Pitkin, E. (2013). Peeking Inside the Black Box: Visualizing Statistical Learning with Plots of Individual Conditional Expectation, 1-22. https://doi.org/10.1080/10618600.2014.907095

See Also

plot.FeatureEffect

Examples

Run this code
# NOT RUN {
# We train a random forest on the Boston dataset:
if (require("rpart")) {
data("Boston", package  = "MASS")
rf = rpart(medv ~ ., data = Boston)
mod = Predictor$new(rf, data = Boston)

# Compute the accumulated local effects for all features
eff = FeatureEffects$new(mod)
eff$plot()

# }
# NOT RUN {
# Again, but this time with a partial dependence plot
eff = FeatureEffects$new(mod, method = "pdp")
eff$plot()

# Only a subset of features
eff = FeatureEffects$new(mod, features = c("nox", "crim"))
eff$plot()


# You can access each FeatureEffect individually

eff.nox = eff$effects[["nox"]]
eff.nox$plot()


# FeatureEffects also works with multiclass classification
rf = rpart(Species ~ ., data = iris)
mod = Predictor$new(rf, data = iris, type = "prob")

FeatureEffects$new(mod)$plot(ncol = 2)
# }
# NOT RUN {
}
# }

Run the code above in your browser using DataLab