plot_metric_density: Density plot for a metric

View source: R/plot_metric_density.R

plot_metric_densityR Documentation

Density plot for a metric

Description

\Sexpr[results=rd, stage=render]{lifecycle::badge("experimental")}

Creates a ggplot2 object with a density plot for one of the columns in the passed data.frame(s).

Note: In its current form, it is mainly intended as a quick way to visualize the results from cross-validations and baselines (random evaluations). It may change significantly in future versions.

Usage

plot_metric_density(
  results = NULL,
  baseline = NULL,
  metric = "",
  fill = c("darkblue", "lightblue"),
  alpha = 0.6,
  theme_fn = ggplot2::theme_minimal,
  xlim = NULL
)

Arguments

results

data.frame with a metric column to create density plot for.

To only plot the baseline, set to NULL.

baseline

data.frame with the random evaluations from baseline(). Should contain a column for the metric.

To only plot the results, set to NULL.

metric

Name of the metric column in `results` to plot. (Character)

fill

Colors of the plotted distributions. The first color is for the `baseline`, the second for the `results`.

alpha

Transparency of the distribution (0 - 1).

theme_fn

The ggplot2 theme function to apply.

xlim

Limits for the x-axis. Can be set to NULL.

E.g. c(0, 1).

Value

A ggplot2 object with the density of a metric, possibly split in 'Results' and 'Baseline'.

Author(s)

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

See Also

Other plotting functions: font(), plot_confusion_matrix(), plot_probabilities(), plot_probabilities_ecdf(), sum_tile_settings()

Examples


# Attach packages
library(cvms)
library(dplyr)

# We will use the musicians and predicted.musicians datasets
musicians
predicted.musicians

# Set seed
set.seed(42)

# Create baseline for targets
bsl <- baseline_multinomial(
  test_data = musicians,
  dependent_col = "Class",
  n = 20  # Normally 100
)

# Evaluate predictions grouped by classifier and fold column
eval <- predicted.musicians %>%
  dplyr::group_by(Classifier, `Fold Column`) %>%
  evaluate(
  target_col = "Target",
  prediction_cols = c("A", "B", "C", "D"),
  type = "multinomial"
)

# Plot density of the Overall Accuracy metric
plot_metric_density(
  results = eval,
  baseline = bsl$random_evaluations,
  metric = "Overall Accuracy",
  xlim = c(0,1)
)

# The bulk of classifier results are much better than
# the baseline results


cvms documentation built on Sept. 11, 2024, 6:22 p.m.