fatf.utils.data.tools.apply_to_column_grouping

fatf.utils.data.tools.apply_to_column_grouping(labels, predictions, row_grouping, fnc)[source]

Applies a function to the specified groups of labels and predictions.

This functions allows to apply a metric for a particular data grouping. The two main applications are group-based fairness and performance evaluation.

Parameters
labelsnumpy.ndarray

A ground truth numpy array.

predictionsnumpy.ndarray

A predictions numpy array.

row_groupingList[List[integer]]

A list of lists representing row indices of the ground truth and prediction arrays resulting in their grouping.

fncCallable[[numpy.ndarray, numpy.ndarray], number]

A function (metric) that will be applied to all of the groups defined by the row_grouping parameter.

Returns
appliedList[numbers]

A list with the fnc function result for every group defined by the row_grouping parameter.

Raises
AttributeError

The fnc parameter does not require two input parameters.

IncorrectShapeError

The labels or predictions parameter is not a 1-dimensional numpy array. The labels and predictions arrays are not of the same length.

TypeError

The row_grouping parameter is not a list. One of the elements of the row_grouping is not a list. Some of the elements in the inner list of the row_grouping list are not integers. The fnc parameter is not a callable (function).

ValueError

The row_grouping parameter is an empty list. Some of the values in the row_grouping list are duplicated.