kwcoco.metrics.functional module

kwcoco.metrics.functional.fast_confusion_matrix(y_true, y_pred, n_labels, sample_weight=None)[source]

faster version of sklearn confusion matrix that avoids the expensive checks and label rectification

Parameters:
  • y_true (ndarray[int]) – ground truth class label for each sample
  • y_pred (ndarray[int]) – predicted class label for each sample
  • n_labels (int) – number of labels
  • sample_weight (ndarray[int|float]) – weight of each sample
Returns:

matrix where rows represent real and cols represent pred and the value at each cell is the total amount of weight

Return type:

ndarray[int64|float64, dim=2]

Example

>>> y_true = np.array([0, 0, 0, 0, 1, 1, 1, 0,  0, 1])
>>> y_pred = np.array([0, 0, 0, 0, 0, 0, 0, 1,  1, 1])
>>> fast_confusion_matrix(y_true, y_pred, 2)
array([[4, 2],
       [3, 1]])
>>> fast_confusion_matrix(y_true, y_pred, 2).ravel()
array([4, 2, 3, 1])