confusion_matrix: Calculate Binary Confusion Matrix

View source: R/confusion_matrix.R

confusion_matrixR Documentation

Calculate Binary Confusion Matrix

Description

Calculates the confusion matrix for a binary classification problem once and then calculates all confusion measures of this package.

Usage

confusion_matrix(truth, response, positive, na_value = NaN, relative = FALSE)

Arguments

truth

(factor())
True (observed) labels. Must have the exactly same two levels and the same length as response.

response

(factor())
Predicted response labels. Must have the exactly same two levels and the same length as truth.

positive

(character(1))
Name of the positive class.

na_value

(numeric(1))
Value that should be returned if the measure is not defined for the input (as described in the note). Default is NaN.

relative

(logical(1))
If TRUE, the returned confusion matrix contains relative frequencies instead of absolute frequencies.

Value

List with two elements:

  • matrix stores the calculated confusion matrix.

  • measures stores the metrics as named numeric vector.

Examples

set.seed(123)
lvls = c("a", "b")
truth = factor(sample(lvls, 20, replace = TRUE), levels = lvls)
response = factor(sample(lvls, 20, replace = TRUE), levels = lvls)

confusion_matrix(truth, response, positive = "a")
confusion_matrix(truth, response, positive = "a", relative = TRUE)
confusion_matrix(truth, response, positive = "b")

mlr3measures documentation built on Aug. 5, 2022, 5:22 p.m.