fatf.utils.metrics.subgroup_metrics.apply_metric_function

fatf.utils.metrics.subgroup_metrics.apply_metric_function(population_confusion_matrix: List[numpy.ndarray], metric_function: Callable[[numpy.ndarray], float], *args, **kwargs) → List[float][source]

Applies the provided performance metric to every confusion matrix.

The performance metric function needs to take a numpy.ndarray confusion matrix as the first parameter followed by any number of unnamed and named parameters provided by *args and **kwargs parameters.

Parameters
population_confusion_matrixList[numpy.ndarray]

A list of confusion matrices for each sub-population.

metric_functionCallable[[numpy.ndarray], Number]

A metric function that takes a confusion matrix as a first parameter, followed by any number of unnamed parameters (*args) and any number of named parameters (**kwargs) and outputs a single number – the metric value.

*args

Unnamed arguments passed to the metric function.

**kwargs

Named arguments passed to the metric function.

Returns
metricsList[numbers]

A list with the value of the selected metric for every sub-population.

Raises
AttributeError

The metric_function parameter does not require at least one unnamed parameter.

IncorrectShapeError

The confusion matrix is not a 2-dimensional numpy array, it is not square (equal width and height) or its dimension is not at least 2x2.

TypeError

The confusion matrix is not of an integer kind (e.g. int, numpy.int32, numpy.int64). One of the metric_function outputs is not numerical. The metric_function is not Python callable. The population_confusion_matrix is not a list.

ValueError

The confusion matrix is a structured numpy array. The population_confusion_matrix parameter is an empty list.