confusion_matrix#

class usencrypt.ai.metrics.confusion_matrix(y_true, y_pred, classes=None)#

Generates a confusion matrix based on ground-truth and prediction labels. Its shape is dependent on the length of the classes, where a classification with \(c\) classes will result in a confusion matrix of shape \(c \times c\).

Parameters
  • y_true (list or numpy.ndarray) – The ground-truth labels.

  • y_pred (list or numpy.ndarray) – The predicted labels.

  • classes (list or numpy.ndarray) – The set of all unique labels in the dataset. Defaults to None. If None, a list of classes will be generated from the dataset.

Returns

Confusion matrix of shape (num_classes, num_classes) based on the true and prediction labels, where the ith row and jth column entries indicate the number of samples with the true label (rows) and predicted label (columns).

Return type

np.ndarray

Examples
>>> import numpy as np
>>> import usencrypt as ue
>>> y_true = np.random.randint(0, 2, size=(10,))
>>> y_true
array([0 0 1 1 1 1 1 0 1 0])
>>> y_pred = np.random.randint(0, 2, size=(10,))
>>> y_pred
array([1 0 0 0 1 0 0 0 0 0])
>>> matrix = ue.ai.metrics.confusion_matrix(y_true, y_pred)
>>> matrix
array([[3 1]
       [5 1]])