fatf.utils.metrics.tools.get_confusion_matrix

fatf.utils.metrics.tools.get_confusion_matrix(ground_truth: numpy.ndarray, predictions: numpy.ndarray, labels: Optional[List[Union[float, str]]] = None) → numpy.ndarray[source]

Computes a confusion matrix based on predictions and ground truth vectors.

The confusion matrix (a.k.a. contingency table) has predictions in rows and ground truth in columns. If the value order is not provide via the labels parameter, the ordering is based on the alphanumeric sorting of the unique values in both of the input arrays.

Parameters
ground_truthnumpy.ndarray

An array holding the true target values.

predictionsnumpy.ndarray

An array holding predictions of the target values.

labelsList[string, number], optional (default=None)

If a certain ordering of the labels in the confusion matrix is desired, it can be specified via this parameter. By default alphanumeric sorting is used.

Returns
confusion_matrixnumpy.ndarray

A confusion matrix.

Raises
IncorrectShapeError

The ground_truth and/or labels vectors are not 1-dimensional. The length of these two arrays does not agree.

TypeError

The labels parameter is not a list.

ValueError

The labels list empty, it contains duplicate entries or some of the labels present in either of the input array are not accounted for by the labels list.

Warns
UserWarning

Some of the labels provided by the user are not present in either of the input arrays.