Plotting Partial Dependence Functions
Plots partial dependence functions (i.e., marginal effects) using
ggplot2
graphics.
## S3 method for class 'partial' autoplot(object, center = FALSE, plot.pdp = TRUE, pdp.color = "red", pdp.size = 1, pdp.linetype = 1, rug = FALSE, smooth = FALSE, smooth.method = "auto", smooth.formula = y ~ x, smooth.span = 0.75, smooth.method.args = list(), contour = FALSE, contour.color = "white", palette = c("viridis", "magma", "inferno", "plasma", "cividis"), train = NULL, xlab = NULL, ylab = NULL, main = NULL, legend.title = "yhat", ...) ## S3 method for class 'ice' autoplot(object, center = FALSE, plot.pdp = TRUE, pdp.color = "red", pdp.size = 1, pdp.linetype = 1, rug = FALSE, train = NULL, xlab = NULL, ylab = NULL, main = NULL, ...) ## S3 method for class 'cice' autoplot(object, plot.pdp = TRUE, pdp.color = "red", pdp.size = 1, pdp.linetype = 1, rug = FALSE, train = NULL, xlab = NULL, ylab = NULL, main = NULL, ...)
object |
An object that inherits from the |
center |
Logical indicating whether or not to produce centered ICE
curves (c-ICE curves). Only useful when |
plot.pdp |
Logical indicating whether or not to plot the partial
dependence function on top of the ICE curves. Default is |
pdp.color |
Character string specifying the color to use for the partial
dependence function when |
pdp.size |
Positive number specifying the line width to use for the
partial dependence function when |
pdp.linetype |
Positive number specifying the line type to use for the
partial dependence function when |
rug |
Logical indicating whether or not to include rug marks on the
predictor axes. Default is |
smooth |
Logical indicating whether or not to overlay a LOESS smooth.
Default is |
smooth.method |
Character string specifying the smoothing method
(function) to use (e.g., |
smooth.formula |
Formula to use in smoothing function (e.g.,
|
smooth.span |
Controls the amount of smoothing for the default loess
smoother. Smaller numbers produce wigglier lines, larger numbers produce
smoother lines. Default is |
smooth.method.args |
List containing additional arguments to be passed
on to the modeling function defined by |
contour |
Logical indicating whether or not to add contour lines to the level plot. |
contour.color |
Character string specifying the color to use for the
contour lines when |
palette |
Character string indicating the colormap option to use. Five options are available: "viridis" (the default), "magma", "inferno", "plasma", and "cividis". |
train |
Data frame containing the original training data. Only required
if |
xlab |
Character string specifying the text for the x-axis label. |
ylab |
Character string specifying the text for the y-axis label. |
main |
Character string specifying the text for the main title of the plot. |
legend.title |
Character string specifying the text for the legend title.
Default is |
... |
Additional optional arguments to be passed onto |
A "ggplot"
object.
## Not run: # # Regression example (requires randomForest package to run) # # Load required packages library(ggplot2) # required to use autoplot library(randomForest) # Fit a random forest to the Boston housing data data (boston) # load the boston housing data set.seed(101) # for reproducibility boston.rf <- randomForest(cmedv ~ ., data = boston) # Partial dependence of cmedv on lstat boston.rf %>% partial(pred.var = "lstat") %>% autoplot(rug = TRUE, train = boston) # Partial dependence of cmedv on lstat and rm boston.rf %>% partial(pred.var = c("lstat", "rm"), chull = TRUE, progress = "text") %>% autoplot(contour = TRUE, legend.title = "rm") # ICE curves and c-ICE curves age.ice <- partial(boston.rf, pred.var = "lstat", ice = TRUE) grid.arrange( autoplot(age.ice, alpha = 0.5), # ICE curves autoplot(age.ice, center = TRUE, alpha = 0.5), # c-ICE curves ncol = 2 ) ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.