plot_confusion_matrix: Plot a confusion matrix

Description Usage Arguments Details Value Examples

View source: R/plot_confusion_matrix.R

Description

Plot a confusion matrix

Usage

1
2
3
4
5
6
plot_confusion_matrix(
  x,
  target_col_name,
  target_pred_col_name,
  type = "heatmap"
)

Arguments

x

A data frame with two columns: the column with the actual classes; and the column with the predicted classes. Any other columns will be ignored.

target_col_name

A string with the column name of the target variable.

target_pred_col_name

A string with the column name of the predictions for the target variable.

type

A string indicating the of plot: "mosaic" or "heatmap". Defaults to- and currntly can only be- "heatmap".

Details

This function differs from ggplot2::autoplot because the gradient fills the heatmap (confusion matrix) based on absolute counts. It does not make sense to compare colours between different "Truth" columns. By contrast plot_confusion_matrix expresses column counts as proportions of the total count in that column. The proportions are used to define a colour scale. The actual counts are plotted though.

Value

A ggplot (ggplot::geom_tile).

Examples

1
2
3
4
5
6
7
library(experienceAnalysis)
mtcars %>%
  dplyr::mutate(carb_pred = sample(carb, size = nrow(.))) %>%  # Mock predictions column
  plot_confusion_matrix(
    target_col_name = "carb",
    target_pred_col_name = "carb_pred"
  )

CDU-data-science-team/experienceAnalysis documentation built on Dec. 17, 2021, 12:53 p.m.