confusion_matrix#

bayesflow.utils.confusion_matrix(targets: ndarray, estimates: ndarray, labels: Sequence = None, normalize: str = None)[source]#

Compute confusion matrix to evaluate the accuracy of a classification or model comparison setting.

Code inspired by: scikit-learn/scikit-learn

Parameters:
targetsnp.ndarray

Ground truth (correct) target values.

estimatesnp.ndarray

Estimated targets as returned by a classifier.

labelsSequence, optional

List of labels to index the matrix. This may be used to reorder or select a subset of labels. If None, labels that appear at least once in y_true or y_pred are used in sorted order.

normalize{‘true’, ‘pred’, ‘all’}, optional

Normalizes confusion matrix over the true (rows), predicted (columns) conditions or all the population. If None, no normalization is applied.

Returns:
cmnp.ndarray of shape (num_labels, num_labels)

Confusion matrix. Rows represent true classes, columns represent predicted classes.