torch_ecg.utils.ovr_confusion_matrix

torch_ecg.utils.ovr_confusion_matrix(labels: ndarray | Tensor, outputs: ndarray | Tensor, num_classes: int | None = None) ndarray

Compute binary one-vs-rest confusion matrices.

Columns are ground truth labels and rows are predicted labels.

Parameters:
  • labels (numpy.ndarray or torch.Tensor) – Binary labels, of shape (n_samples, n_classes), or indices of each label class, of shape (n_samples,).

  • outputs (numpy.ndarray or torch.Tensor) – Binary outputs, of shape (n_samples, n_classes), or indices of each class predicted, of shape (n_samples,).

  • num_classes (int, optional) – number of classes. If labels and outputs are both of shape (n_samples,), then num_classes must be specified.

Returns:

ovr_cm – One-vs-rest confusion matrix, of shape (n_classes, 2, 2).

Return type:

numpy.ndarray