confusion_matrix: Confusion matrix construction

View source: R/confusion_matrix.R

confusion_matrixR Documentation

Confusion matrix construction

Description

Construct confusion matrix based on matrix form input. The confusion matrix is tipically defined with respect to some learning algorithm. The diagonal entries denote the correctly classified examples for respective class. All the nondiagonal entries denote misclassifications.

Usage

confusion_matrix(y_real, y_predicted, threshold = 0.5)

Arguments

y_real

Observed values (integers) to compare with (in matrix format for multiclass classification).

y_predicted

Predicte values (probabiblities by class).

threshold

Used in binary classification case. Defines the threshold of success in the classification output. The decision rule applied is greater or equal.

Value

matrix Confusion matrix.

Examples

# Assuming data is:
y_real <- matrix(
  c(
    1, 0, 0,
    0, 1, 0,
    0, 0, 1
  ),
  ncol = 3, byrow = TRUE
)
y_predicted <- matrix(
  c(
    0.6, 0.1, 0.3,
    0.7, 0.2, 0.1,
    0.2, 0.3, 0.5
  ),
  ncol = 3, byrow = TRUE
)

# Resulting confusion matrix is:
confusion_matrix(y_real, y_predicted)


nikitagusarov/performancer documentation built on Jan. 12, 2023, 12:19 a.m.