ice {hstats} | R Documentation |
Individual Conditional Expectations
Description
Disaggregated partial dependencies, see reference. The plot method supports
up to two grouping variables via BY
.
Usage
ice(object, ...)
## Default S3 method:
ice(
object,
v,
X,
pred_fun = stats::predict,
BY = NULL,
grid = NULL,
grid_size = 49L,
trim = c(0.01, 0.99),
strategy = c("uniform", "quantile"),
na.rm = TRUE,
n_max = 100L,
...
)
## S3 method for class 'ranger'
ice(
object,
v,
X,
pred_fun = function(m, X, ...) stats::predict(m, X, ...)$predictions,
BY = NULL,
grid = NULL,
grid_size = 49L,
trim = c(0.01, 0.99),
strategy = c("uniform", "quantile"),
na.rm = TRUE,
n_max = 100L,
...
)
## S3 method for class 'explainer'
ice(
object,
v = v,
X = object[["data"]],
pred_fun = object[["predict_function"]],
BY = NULL,
grid = NULL,
grid_size = 49L,
trim = c(0.01, 0.99),
strategy = c("uniform", "quantile"),
na.rm = TRUE,
n_max = 100L,
...
)
Arguments
object |
Fitted model object. |
... |
Additional arguments passed to |
v |
One or more column names over which you want to calculate the ICE. |
X |
A data.frame or matrix serving as background dataset. |
pred_fun |
Prediction function of the form |
BY |
Optional grouping vector/matrix/data.frame (up to two columns),
or up to two column names. Unlike with |
grid |
Evaluation grid. A vector (if |
grid_size |
Controls the approximate grid size. If |
trim |
The default |
strategy |
How to find grid values of non-discrete numeric columns?
Either "uniform" or "quantile", see description of |
na.rm |
Should missing values be dropped from the grid? Default is |
n_max |
If |
Value
An object of class "ice" containing these elements:
-
data
: data.frame containing the ice values. -
grid
: Vector, matrix or data.frame of grid values. -
v
: Same as inputv
. -
K
: Number of columns of prediction matrix. -
pred_names
: Column names of prediction matrix. -
by_names
: Column name(s) of grouping variable(s) (orNULL
).
Methods (by class)
-
ice(default)
: Default method. -
ice(ranger)
: Method for "ranger" models. -
ice(explainer)
: Method for DALEX "explainer".
References
Goldstein, Alex, and Adam Kapelner and Justin Bleich and Emil Pitkin. Peeking inside the black box: Visualizing statistical learning with plots of individual conditional expectation. Journal of Computational and Graphical Statistics, 24, no. 1 (2015): 44-65.
Examples
# MODEL 1: Linear regression
fit <- lm(Sepal.Length ~ . + Species * Petal.Length, data = iris)
plot(ice(fit, v = "Sepal.Width", X = iris))
# Stratified by one variable
ic <- ice(fit, v = "Petal.Length", X = iris, BY = "Species")
ic
plot(ic)
plot(ic, center = TRUE)
## Not run:
# Stratified by two variables (the second one goes into facets)
ic <- ice(fit, v = "Petal.Length", X = iris, BY = c("Petal.Width", "Species"))
plot(ic)
plot(ic, center = TRUE)
# MODEL 2: Multi-response linear regression
fit <- lm(as.matrix(iris[, 1:2]) ~ Petal.Length + Petal.Width * Species, data = iris)
ic <- ice(fit, v = "Petal.Width", X = iris, BY = iris$Species)
plot(ic)
plot(ic, center = TRUE)
plot(ic, swap_dim = TRUE)
## End(Not run)
# MODEL 3: Gamma GLM -> pass options to predict() via ...
fit <- glm(Sepal.Length ~ ., data = iris, family = Gamma(link = log))
plot(ice(fit, v = "Petal.Length", X = iris, BY = "Species"))
plot(ice(fit, v = "Petal.Length", X = iris, type = "response", BY = "Species"))