torch_ecg.utils.confusion_matrix#
- torch_ecg.utils.confusion_matrix(labels: ndarray | Tensor, outputs: ndarray | Tensor, num_classes: int | None = None) ndarray[source]#
Compute a binary confusion matrix
The 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:
cm – Confusion matrix, of shape
(n_classes, n_classes).- Return type: