
Plot models on any two or three metrics, static or interactive
Source:R/plot_models.R
plot_models.RdOne function for every view of a model comparison: choose the metrics
for the axes (e.g. bias against AUC, MAEbal against AUC, or AUC, MAEbal
and bias in 3-D), and whether the plot is a static ggplot or an
interactive one (package plotly) that can be rotated, zoomed and
hovered over in the RStudio viewer or a browser, and saved as an HTML
file.
Usage
plot_models(
object,
x = NULL,
y = NULL,
z = NULL,
interactive = !is.null(z),
zoom = FALSE,
labels = TRUE,
error_bars = TRUE,
bar_colour = "#c8553d",
directions = NULL,
file = NULL,
browse = interactive(),
width = 2100,
height = 1500,
base_size = 12
)Arguments
- object
Output of
select_models(),evaluate_models()orevaluate_cv(), or any data.frame with amodelcolumn and one column per metric.- x, y, z
Metrics (column names) for the axes. Default: the second and first criterion of
object(e.g. MAE and AUC).zadds a third axis (3-D, interactive).- interactive
Draw with
plotly(defaultTRUEfor 3-D,FALSEfor 2-D).- zoom
For static 2-D plots:
TRUEto show only the region of the best models, or axis limits; seeplot_selection().- labels
Show model names.
- error_bars
Draw error bars (bootstrap intervals, else +/- 1 SD).
- bar_colour
Colour of the error bars.
- directions
Optional named vector of directions for metrics the package does not know, e.g.
c(fossil_AUC_deep = "max")("max","min","zero"or"one"). Known: the criteria ofobject, AUC, MAE, MAEbal, bias, TSS, Boyce, calibration_slope, calibration_intercept, brier, Boyce_smooth and any column ending in_AUC*,_sens,_lift(higher is better) or_area(lower is better).- file
Optional file(s) to save the plot to. Interactive plots: an
.htmlfile. Static plots: e.g."fig.pdf"orc("fig.png", "fig.pdf"); a name without extension is saved as PNG and PDF.- browse
Open the saved file in the web browser.
- width, height
Size of the saved figure in pixels (PDF and SVG at 300 pixels per inch).
- base_size
Base font size of static plots.
Value
A ggplot (static) or plotly object (interactive). Printing an
interactive plot opens it in the RStudio viewer or the browser.
Details
With two metrics and
interactive = FALSE, the plot is the same asplot_selection()(forselect_models()output) orplot_pareto()(forevaluate_models()output), includingzoom.With
z, the plot is 3-D and always interactive.
Axes are oriented so that better is always away from the origin
("lower is better" axes are reversed). Colours show the selection
(selected / not selected) or, for a bootstrapped evaluation, the share
of resamples in which the model was on the Pareto front; circles are
Pareto-front models and squares dominated ones. Bars show the SD across
runs (<metric>_sd) or the bootstrap intervals (<metric>_lower,
<metric>_upper) when present.
Examples
df <- data.frame(model = c("GLM", "GBM", "RF", "MAXNET", "SRE"),
AUC = c(0.918, 0.919, 0.912, 0.918, 0.701),
MAEbal = c(0.218, 0.236, 0.204, 0.332, 0.299),
bias = c(-0.04, -0.05, -0.02, 0.10, -0.18),
TSS = c(0.70, 0.71, 0.57, 0.71, 0))
sel <- select_models(df, criteria = c(AUC = "max", MAEbal = "min"),
plot = FALSE)
plot_models(sel, x = "bias", y = "AUC")
plot_models(sel, x = "MAEbal", y = "AUC", zoom = TRUE)
if (requireNamespace("plotly", quietly = TRUE)) {
plot_models(sel, x = "MAEbal", y = "AUC", z = "bias") # 3-D
}