confusion_matrix()

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

Confusion matrix.

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

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

  • labels (Optional[Sequence[Any]]) – 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[Union[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]]