Learn R Programming

iml (version 0.6.0)

Interaction: Feature interactions

Description

Interaction estimates the feature interactions in a prediction model.

Format

R6Class object.

Usage

ia = Interaction$new(predictor, feature = NULL, grid.size = 20, run = TRUE)

plot(ia) ia$results print(ia)

Arguments

For Interaction$new():

predictor:

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

feature:

(`numeric(1)`|NULL) If NULL, for each feature the interactions with all other features are estimated. If one feature name is selected, the 2-way interactions of this feature with all other features are estimated

grid.size:

(`logical(1)`) The number of values per feature that should be used to estimate the interaction strength. A larger grid.size means more accurate the results but longer the computation time. For each of the grid points, the partial dependence functions have to be computed, which involves marginalizing over all data points.

parallel:

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

run:

(`logical(1)`) Should the Interpretation method be run?

Fields

grid.size:

(`logical(1)`) The number of values per feature that should be used to estimate the interaction strength.

predictor:

(Predictor) The prediction model that was analysed.

results:

(data.frame) Data.frame with the interaction strength (column '.interation') per feature calculated as Friedman's H-statistic and - in the case of a multi-dimensional outcome - per class.

Methods

plot()

method to plot the feature interactions. See plot.Interaction.

run()

[internal] method to run the interpretability method. Use obj$run(force = TRUE) to force a rerun.

clone()

[internal] method to clone the R6 object.

initialize()

[internal] method to initialize the R6 object.

Details

Interactions between features are measured via the decomposition of the prediction function: If a feature j has no interaction with any other feature, the prediction function can be expressed as the sum of the partial function that depends only on j and the partial function that only depends on features other than j. If the variance of the full function is completely explained by the sum of the partial functions, there is no interaction between feature j and the other features. Any variance that is not explained can be attributed to the interaction and is used as a measure of interaction strength.

The interaction strength between two features is the proportion of the variance of the 2-dimensional partial dependence function that is not explained by the sum of the two 1-dimensional partial dependence functions.

The interaction is measured by Friedman's H-statistic (square root of the H-squared test statistic) and takes on values between 0 (no interaction) to 1 (100

References

Friedman, Jerome H., and Bogdan E. Popescu. "Predictive learning via rule ensembles." The Annals of Applied Statistics 2.3 (2008): 916-954.

Examples

Run this code
# NOT RUN {
if (require("rpart")) {
set.seed(42)
# Fit a CART on the Boston housing data set
data("Boston", package  = "MASS")
rf = rpart(medv ~ ., data = Boston)
# Create a model object
mod = Predictor$new(rf, data = Boston[-which(names(Boston) == "medv")]) 

# Measure the interaction strength
ia = Interaction$new(mod)

# Plot the resulting leaf nodes
plot(ia) 


# Extract the results 
dat = ia$results
head(dat)
# }
# NOT RUN {
# Interaction also works with multiclass classification
rf = rpart(Species ~ ., data = iris)
mod = Predictor$new(rf, data = iris, type = "prob")

# For some models we have to specify additional arguments for the predict function
ia = Interaction$new(mod)

ia$plot()

# For multiclass classification models, you can choose to only show one class:
mod = Predictor$new(rf, data = iris, type = "prob", class = "virginica")
plot(Interaction$new(mod))
# }
# NOT RUN {
}
# }

Run the code above in your browser using DataLab