Skip to contents

Accepts a square count matrix, a named list of count matrices, long frequency records (reference, predicted, n, optional panel), or paired reference and predicted label vectors. Model packages can add support for metrics objects through confusion_input(). Matrix columns are aligned by label identity; their physical order need not match rows. All panels share one class order.

Usage

draw_confusion(
  x,
  y = NULL,
  classes = NULL,
  ...,
  theme = NULL,
  width = NULL,
  height = NULL,
  element_id = NULL,
  filename = NULL
)

Arguments

x

Matrix, table, data frame, named list, metrics object, or vector: Counts or reference labels.

y

Optional vector: Predicted labels when x contains reference labels.

classes

Optional Character vector: Ordered class labels shared by every panel; unset preserves first appearance.

...

Additional named settings for setup_ConfusionConfig().

theme

Optional Theme: Chart theme. Color fades and marginal backgrounds follow the active theme unless overridden in the config.

width, height

Optional Numeric or Character: Widget dimensions.

element_id

Optional Character: HTML element identifier.

filename

Optional Character: Static output path, currently SVG.

Value

An ECharts htmlwidget containing every requested panel.

Statistical semantics

Color intensity is the fraction within each reference row; labels show raw counts. Sensitivity, specificity, PPV, and NPV are one-versus-rest rates for each named class. Balanced accuracy is mean class recall, including every declared class. Zero denominators produce NA, never zero; consequently balanced accuracy is NA if any declared class has no reference observations. Summaries of pooled resamples describe pooled predictions, not mean fold performance. Repeated observations are counted each time they appear.

Examples

draw_confusion(factor(c("yes", "yes", "no")), c("yes", "no", "no"))
draw_confusion(matrix(c(8, 2, 1, 9), 2,
  dimnames = list(c("yes", "no"), c("yes", "no"))))