plot_metric_density function

Density plot for a metric

Density plot for a metric

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.

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).

Returns

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

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

See Also

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

Author(s)

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

  • Maintainer: Ludvig Renbo Olsen
  • License: MIT + file LICENSE
  • Last published: 2025-03-07