confusion_matrix: Calculate various statistics from a confusion matrix

Description Usage Arguments Details Value References See Also Examples

View source: R/confusion_matrix.R

Description

Given a vector of predictions and target values, calculate numerous statistics of interest.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
confusion_matrix(
  prediction,
  target,
  positive = NULL,
  prevalence = NULL,
  return_table = FALSE,
  dnn = c("Predicted", "Target"),
  longer = FALSE,
  ...
)

Arguments

prediction

A vector of predictions

target

A vector of target values

positive

The positive class for a 2-class setting. Default is NULL, which will result in using the first level of target.

prevalence

Prevalence rate. Default is NULL.

return_table

Logical. Whether to return the table of prediction vs. target. Default is FALSE. Cannot have both return_table and longer TRUE.

dnn

The row and column headers for the table returned by return_table. Default is 'Predicted' for rows and 'Target' for columns.

longer

Transpose the output to long form. Default is FALSE (requires tidyr 1.0). Cannot have both return_table and longer TRUE.

...

Other parameters, not currently used.

Details

This returns accuracy, agreement, and other statistics. See the functions below to find out more. Originally inspired by the confusionMatrix function from the caret package.

Value

A list of tibble(s) with the associated statistics and possibly the frequency table as list column of the first element.

References

Kuhn, M., & Johnson, K. (2013). Applied predictive modeling.

See Also

confusionMatrix calc_accuracy calc_agreement calc_stats

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
library(confusionMatrix)

p = c(0,1,1,0,0,1,0,1,1,1)
o = c(0,1,1,1,0,1,0,1,0,1)

confusion_matrix(p, o, return_table = TRUE, positive = '1')

p = sample(letters[1:4], 250, replace = TRUE, prob = 1:4)
o = sample(letters[1:4], 250, replace = TRUE, prob = 1:4)

confusion_matrix(p, o, return_table = TRUE)

m-clark/confusionMatrix documentation built on July 15, 2020, 4:16 p.m.