average_predicted {effectplots} | R Documentation |
Calculates average predictions over the values of one or multiple
X
variables. Shows the combined effect of a feature and other (correlated)
features.
average_predicted(
X,
pred,
w = NULL,
x_name = "x",
breaks = "Sturges",
right = TRUE,
discrete_m = 5L,
outlier_iqr = 2,
seed = NULL,
...
)
X |
A vector, matrix, or data.frame with variable(s) to be shown on the x axis. |
pred |
A numeric vector of predictions. |
w |
An optional numeric vector of weights. |
x_name |
If |
breaks |
An integer, vector, string or function specifying the bins
of the numeric X variables as in |
right |
Should bins be right-closed? The default is |
discrete_m |
Numeric X variables with up to this number of unique values
should not be binned and treated as a factor (after calculating partial dependence)
The default is 5. Vectorized over |
outlier_iqr |
Outliers of a numeric X are capped via the boxplot rule, i.e.,
outside |
seed |
Optional random seed (an integer) used for capping X based on quantiles calculated from a subsample of 10k observations. |
... |
Currently unused. |
The function is a convenience wrapper around feature_effects()
.
A list (of class "EffectData") with a data.frame of statistics per feature. Use single bracket subsetting to select part of the output.
Apley, Daniel W., and Jingyu Zhu. 2016. Visualizing the Effects of Predictor Variables in Black Box Supervised Learning Models. Journal of the Royal Statistical Society Series B: Statistical Methodology, 82 (4): 1059–1086. doi:10.1111/rssb.12377.
fit <- lm(Sepal.Length ~ ., data = iris)
M <- average_predicted(iris[2:5], pred = predict(fit, iris), breaks = 5)
M
M |> plot()