confusion_matrix()

audmetric.confusion_matrix(truth, prediction, labels=None, *, normalize=False)[source]

Confusion matrix.

Parameters
  • truth (Sequence[object]) – ground truth values/classes

  • prediction (Sequence[object]) – predicted values/classes

  • labels (Sequence[object]) – included labels in preferred ordering. If no labels are supplied, they will be inferred from {prediction,truth}\{\text{prediction}, \text{truth}\} and ordered alphabetically.

  • normalize (bool) – normalize confusion matrix over the rows

Return type

list[list[int | float]]

Returns

confusion matrix

Raises

ValueError – if truth and prediction differ in length

Examples

>>> truth = [0, 1, 2]
>>> prediction = [0, 2, 0]
>>> confusion_matrix(truth, prediction)
[[1, 0, 0], [0, 0, 1], [1, 0, 0]]