Skip to contents

Plot the raw or summarized prediction errors as a boxplot, scatter plot, line plot, or bar plot with or without 1 SD error bars.

Usage

plot_pred_err(
  fit_results,
  eval_results = NULL,
  evaluator_name = NULL,
  vary_params = NULL,
  metrics = NULL,
  show = c("point", "line"),
  ...
)

Arguments

fit_results

A tibble, as returned by the fit method.

eval_results

A list of result tibbles, as returned by the evaluate method.

evaluator_name

Name of Evaluator containing results to plot. To compute the evaluation summary results from scratch or if the evaluation summary results have not yet been evaluated, set to NULL.

vary_params

A vector of parameter names that are varied across in the Experiment.

metrics

A metric_set object indicating the metrics to plot. See yardstick::metric_set() for more details. Default NULL will use the default metrics in yardstick::metrics().

show

Character vector with elements being one of "boxplot", "point", "line", "bar", "errorbar", "ribbon" indicating what plot layer(s) to construct.

...

Additional arguments to pass to plot_eval_summary(). This includes arguments for plotting and for passing into summarize_pred_err().

Value

If interactive = TRUE, returns a plotly object if plot_by is NULL and a list of plotly objects if plot_by is not NULL. If interactive = FALSE, returns a ggplot object if plot_by is NULL and a list of ggplot objects if plot_by is not NULL.

See also

Examples

# generate example fit_results data
fit_results <- tibble::tibble(
  .rep = rep(1:2, times = 2),
  .dgp_name = c("DGP1", "DGP1", "DGP2", "DGP2"),
  .method_name = c("Method"),
  # true response
  y = lapply(1:4, FUN = function(x) rnorm(100)),
  # predicted response
  predictions = lapply(1:4, FUN = function(x) rnorm(100))
)

# generate example eval_results data
eval_results <- list(
  `Prediction Errors` = summarize_pred_err(
    fit_results, truth_col = "y", estimate_col = "predictions"
  )
)

# create errorbar plot using pre-computed evaluation results
plt <- plot_pred_err(fit_results = fit_results, eval_results = eval_results,
                     evaluator_name = "Prediction Errors",
                     show = c("point", "errorbar"))
# or alternatively, create the same plot without pre-computing evaluation results
plt <- plot_pred_err(fit_results, show = c("point", "errorbar"),
                     truth_col = "y", estimate_col = "predictions")

# can customize plot (see plot_eval_summary() for possible arguments)
plt <- plot_pred_err(fit_results = fit_results, eval_results = eval_results,
                     evaluator_name = "Prediction Errors",
                     show = c("point", "errorbar"), 
                     color_str = NULL,
                     facet_formula = .method_name ~ .metric,
                     facet_type = "grid")